私はおそらく何かが分かりませんが、ファイルに書き込むたびに、入力したテキストはドキュメントを開くと2行目に表示されます。これを引き起こしているのは何ですか?ファイルへの書き込みはどこから来ますか?
#include <stdio.h>
int main()
{
char c;
char filename[100];
FILE *fp;
printf("Type the name of the file to write to followed by enter: \n\n");
scanf("%[^\t\n]s", filename);
fp = fopen(filename, "w");
printf("\n\nEnter the text you wish to write to this file: \n\n");
while ((c = getchar()) != EOF)
{
putc(c, fp);
}
return 0;
}
を使用? – bqui56
@ stariz77:申し訳ありませんが、それはタイプミスでした。私は 'getchar'を意味しました。 –