사용자가 단어를 입력하고 프로그램에서 입력 한 단어를 검색 할 수있는 프로그램을 만들려고합니다. 나는 무엇을 내 프로그램에서 발생하는 그러나 나는 단어를 입력대로에 내가 입력 해요 char 배열의 0에서 시작하지 않는다는 것입니다 생각사용자가 파일에서 단어를 검색 할 수있게 해주는 프로그램
가로 다시 읽도록#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int num =0;
char word[2000];
char *string;
FILE *in_file = fopen("words.txt", "r");
//FILE *out_file = fopen("output.txt", "w");
if (in_file == NULL)
{
printf("Error file missing\n");
exit(-1);
}
while(word[0]!= '0')
{
printf("please enter a word(enter 0 to end)\n");
scanf("%s",word);
while(!feof(in_file))
{
fscanf(in_file,"%s",string);
if(!strcmp(string,word))//if match found
num++;
}
printf("we found the word %s in the file %d times\n",word,num);
num = 0;
}
return 0;
}
누군가가 나를 도울 수 정확한 위치? 그래서 그것이 단어를 비교하러 갈 때 그것은 그렇게 정확하게합니까?
관련 : http://stackoverflow.com/q/15508828/509868 – anatolyg