0
1つのテキストファイルに単語を追加するプログラムを作成しようとしています。また、私はこのファイルから任意の単語を削除することができ、私はこの単語なしで結果を別のテキストファイルに保存します。しかし、私はそれを実行すると、私の2番目のテキストファイルは、Hのシンボルで満たされ、そのサイズは100 MB以上になることができます。このコードで何が問題になっていますか?ここにあります:出力ファイルがH記号で埋められています。C
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);
}