| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 534 人关注过本帖
标题:求助:请问如何编这样的一个程序
只看楼主 加入收藏
木鸡
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-1-19
收藏
 问题点数:0 回复次数:2 
求助:请问如何编这样的一个程序
求助:请问如何编这样的一个程序

我要在一个文本文件中搜索一些固定的词语,然后输出固定的词语后面的内容。

比如这样一个文本文件,他的内容是:

TOOL:R5
SINA SIHU YAHUU
.....
.......
PRO:1500
..........


假设上面一个文本文件里面的内容,现在我要在不打开这个文本文件的情况下,通过程序搜索这个文本文件里面的内容,
然后通过找里面的关键字,比如上面的“TOOL:”是关键字,我只要一搜索到“TOOL:”这个词,就输出它后面的内容,比如输出上面的R5。


跪求高手指点!!!木鸡感激不尽!!

搜索更多相关主题的帖子: 如何 文本文件 
2006-01-19 17:50
love_me
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2005-12-29
收藏
得分:0 

Find a character in a string.
char *strchr( const char *string, int c
);wchar_t *wcschr( const wchar_t *string, wchar_t c
);unsigned char *_mbschr( const unsigned char *string, unsigned int c
);
Parameters
string
Null-terminated source string.
c
Character to be located.
Return Value
Each of these functions returns a pointer to the first occurrence of c in string, or NULL if c is not found.
Remarks
The strchr function finds the first occurrence of c in string, or it returns NULL if c is not found. The null-terminating character is included in the search.
wcschr and _mbschr are wide-character and multibyte-character versions of strchr. The arguments and return value of wcschr are wide-character strings; those of _mbschr are multibyte-character strings. _mbschr recognizes multibyte-character sequences according to the multibyte code page currently in use. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H routine
_UNICODE & _MBCS not defined
_MBCS defined
_UNICODE defined
_tcschr
strchr
_mbschr
wcschr
Requirements
Routine
Required header
Compatibility
strchr
<string.h>
ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
wcschr
<string.h> or <wchar.h>
ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
_mbschr
<mbstring.h>
Win 98, Win Me, Win NT, Win 2000, Win XP
For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
Example
// crt_strchr.c
/*
This program illustrates searching for a character
with strchr (search forward) or strrchr (search backward).
*/

#include <string.h>
#include <stdio.h>

int ch = 'r';

char string[] = "The quick brown dog jumps over the lazy fox";
char fmt1[] = " 1 2 3 4 5";
char fmt2[] = "12345678901234567890123456789012345678901234567890";

int main( void )
{
char *pdest;
int result;

printf( "String to be searched:\n %s\n", string );
printf( " %s\n %s\n\n", fmt1, fmt2 );
printf( "Search char: %c\n", ch );

/* Search forward. */
pdest = strchr( string, ch );
result = (int)(pdest - string + 1);
if ( pdest != NULL )
printf( "Result: first %c found at position %d\n",
ch, result );
else
printf( "Result: %c not found\n" );

/* Search backward. */
pdest = strrchr( string, ch );
result = (int)(pdest - string + 1);
if ( pdest != NULL )
printf( "Result: last %c found at position %d\n", ch, result );
else
printf( "Result:\t%c not found\n", ch );
}
Output
String to be searched:
The quick brown dog jumps over the lazy fox
1 2 3 4 5
12345678901234567890123456789012345678901234567890

Search char: r
Result: first r found at position 12
Result: last r found at position 30
See Also
String Manipulation Routines | strcspn | strncat | strncmp | strncpy | _strnicmp | strpbrk | strrchr | strstr | Run-Time Routines and .NET Framework Equivalents


Send feedback on this topic to Microsoft
(c) Microsoft Corporation. All rights reserved.

[此贴子已经被作者于2006-1-19 19:03:03编辑过]


灌水无罪! 顶贴有理! <0_0>
2006-01-19 18:58
bullbatLT
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-1-13
收藏
得分:0 
在C++论坛那已经给你回复了,又来VC这发了[em09

2006-01-25 11:36
快速回复:求助:请问如何编这样的一个程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041269 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved