ファイル内の2つの特定の単語を行ごとに検索し、存在する場合は「Found!」と出力する必要があります。
これはfile.txtです(4つの列があります)
bill gates 62bill microsoft
beyonce knowles 300mill entertainment
my name -$9000 student
以下は私が持っていたアイデアですが、うまくいかないようです
char firstname[];
char lastname[];
char string_0[256];
file = fopen("file.txt","r+");
while((fgets(string_0,256,file)) != NULL) {
//scans the line then sets 1st and 2nd word to those variables
fscanf(file,"%s %s",&firstname, &lastname);
if(strcmp(firstname,"beyonce")==0 && strcmp(lastname,"knowles")==0){
printf("A match has been found");
}
}
fclose(file);
助けてください。whileループの次の行にポインタが移動していない可能性がありますか?もしそうなら、どうすれば修正できますか?