ファイルを更新して比較したい。次の結果を得るためにコードを書くにはどうすればよいですか?
最初にプログラムを実行し、データを取得akon : 5
します。txt ファイルに保存する必要があります。
akon : 5
2 回目の実行、データの取得john : 10
akon : 5
john : 10
3 回目の実行、データの取得akon : 2
akon : 2
john :10
4 回目の実行、データの取得akon : 3
akon : 3
john : 10
以下は私が入力したコードですが、ここで立ち往生しています。
FILE *out_file;
char name[100];
int score;
printf("please enter name:");
gets(name);
printf("please enter the score:");
scanf("%d",&score);
out_file= fopen("C:\\Users/leon/Desktop/New Text Document.txt", "w"); // write only
// test for files not existing.
if (out_file == NULL)
{
printf("Error! Could not open file\n");
exit(-1); // must include stdlib.h
}
// write to file
fprintf(out_file, "%s : %d",name,score); // write to file