簡體   English   中英

使用文件實現復制命令我的代碼正在復制垃圾?

[英]implementing copy command using file my code is copying garbage?

使用文件實現復制命令我的代碼正在復制垃圾。請幫助我修復

   #include<stdio.h>
    int main()
{
    char ch;
    FILE *fp,*fp1;
    fp=fopen("source","r");
    if(fp==NULL)
    {
            printf("no file\n");
            return;
    }
    else
    {
            printf("file is present\n");
            fp1=fopen("dest","w");
            while(ch=fgetc(fp)!=EOF)
            fputc(ch,fp1); // why source contain is not copyed to dest?
    }
             fclose(fp);
             fclose(fp1);
}
while(ch=fgetc(fp)!=EOF)

等價於:

while(ch = (fgetc(fp)!=EOF))

因此根據fgetc(fp)!=EOF)是true來給ch10 您想要的是:

while((ch = fgetc(fp)) != EOF)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM