特定文本的两行之间的文件和提取行我想提取文本是在[曲棍球]之间,并从以下文件[曲棍球做]:阅读用C
sport.txt
:
[HOCKEY]
a=10
b=20
c=30
d=45
[done with HOCKEY]
[SOCCER]
a=35
b=99
c=123
d=145
[done with SOCCER]
用下面的代码,我就能检查线[曲棍球]但我无法拍摄到一号线[曲棍球]之间的位置和最后一行[曲棍球做]
#include<stdio.h>
int main()
{
FILE *infile;
char start, end;
char *sport="[]";
char line_buffer[BUFSIZ]; /* BUFSIZ is defined if you include stdio.h */
int line_number,i;
infile = fopen("sport.txt", "r");
printf("Opened file for reading\n");
line_number = 0;
while (fgets(line_buffer, sizeof(line_buffer), infile)) {
++line_number;
/* note that the newline is in the buffer */
if (line_buffer=="[HOCKEY]")
{
start=line_buffer;
printf("Found start %s",start);
}
if (line_buffer=="[done with HOCKEY]")
end=line_buffer;
while(start<end){
printf("%c",start);
start++;
system("PAUSE");
}
}
return 0;
}
究竟是什么问题? – herohuyongtao
需要学习如何处理C中的字符串。 – BLUEPIXY