0
これは、1つのファイルから別のファイルにコンテンツをコピーするためのプログラムです。私のコードが期待どおりに動くようにオンラインコンパイラでEOFを指定する方法は?指定方法jdoodleのようなCオンラインコンパイラでファイルの終わり(EOF)を指定するには?
オンラインエディタのリンク---> https://www.jdoodle.com/c-online-compiler
//コンテンツをコピーするためのコード--- >>
#include "stdio.h"
int main()
{
char ch;
FILE *p,*q;
p=fopen("data.txt","w");
while(ch=getchar()!=EOF)
{
putc(ch,p);
}
fclose(p);
p=fopen("data.txt","r");
q=fopen("newdata.txt","w");
while(ch=getc(p)!=EOF)
{
putc(ch,q);
}
fclose(p);
fclose(q);
q=fopen("newdata.txt","r");
while(ch=getc(q)!=EOF)
{
printf("\n%c",ch);
}
}
あなたの2番目のポイントは正しいです。しかし、Istポイントgetchar()は、キーボードから入力を読み込むために使用される関数です。一度に1文字ずつ読み込みます。 – rohitgoelrg
@rohitgoelrg [読んで理解してください](https://stackoverflow.com/questions/35356322/difference-between-int-and-char-in-getchar-fgetc-and-putchar-fputc) –