似乎无法找到任何关于如何从.txt文件中的特定行中找到信息的信息。 欲行可能是从冰球比赛的结果, 行可能看起来像:查找文本文件中某一行的特定信息
19.00 01.01.2010 TEAM1 - 5的Team2 - 10 2000
20.00 2010年2月20日的Team2 - Team3 7 - 11 3400
19.00 2010年3月30日TEAM1 - Team4 4 - 4 1000
等等...
因此,如果我只想从team3和team4的比赛中获得外线打印?
这是我目前所拥有的,但是如果我想输入2 - 2并获取其中有数字2的每一行。
谢谢
#include <stdio.h>
#include <string.h>
int main (void){
char target [ 64 ];
printf("Enter a score:");
scanf("%s",&target);
static const char filNavn[] = "text";
FILE *fil = fopen(filNavn, "r");
if (fil != NULL){
char line [ 64 ];
while(fgets(line, sizeof line, fil) != NULL){
if (strstr(line, target) != NULL){
printf("%s\n", line);
}
}
fclose(fil);
}
else{
perror(filNavn);
}
return 0;
}
你应该列出你想要显示的所有组合和一些文件内容的例子。 –
好吧,我在 – Winkz