I'm trying to write a program where I add words to one text file. Also, I can delete any word from this file and I save the result without this word to another text file. But when I run it, my second text file is filled with H symbols, and its size can be more than 100 mb. What's wrong with this code? Here it is:
int main(void)
{
int wordNumbers;
int i;
char buf[512];
char word[128];
FILE *o_file = fopen("C:\\atest.txt", "a");
FILE *s_file = fopen("C:\\btest.txt", "w");
printf("please add an amount of words of the dictionary ");
scanf("%i", &wordNumbers);
for (i=0; i< wordNumbers; i++)
{ char word[100] = {0};
printf("add a word into the dictionary please\n");
scanf("%s", &word);
fprintf(o_file, "%s\n", word);
}
if(!o_file || !s_file) return -1;
printf("please write down the word you want to delete\n");
scanf("%s",&word);
do
{
fscanf(o_file, "%511s", buf);
if(!strcmp(buf, word))
continue;
fprintf(s_file, "%s\n", buf);
}
while(!feof(o_file));
fclose(o_file);
fclose(s_file);
}