`

文件复制

阅读更多

#include "stdio.h"

int main(int argCount, char *argValue[]){
    FILE* srcFile=0;
    FILE* desFile=0;
    int ch=0;
    if(argCount!=3){
        printf("Usage:%s sourcefile destinationfile\n",argValue[0]);
    }else{
        if((srcFile=fopen(argValue[1],"r"))==0){
            printf("cannot open source file %s",argValue[1]);
        }else{
            if((desFile=fopen(argValue[2],"w"))==0){
              printf("cannot open destination file %s",argValue[0]);
              fclose(srcFile);
            }else{
                while((ch=fgetc(srcFile))!=EOF)
                    fputc(ch,desFile);
                printf("Successful to copy a file/n");
                fclose(srcFile);
                fclose(desFile);
                return 0;
            }
        }
    }
    return 1;
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics