c语言 13-13

1、

#include <stdio.h>

int main(void)
{
    int ch;
    FILE *sfp;
    FILE *dfp;
    char sfile[FILENAME_MAX];
    char dfile[FILENAME_MAX];
    printf("source file name: "); scanf("%s", sfile);
    printf("destinatiom file name: "); scanf("%s", dfile);
    
    if((sfp = fopen(sfile, "rb")) == NULL)
        printf("\aSfile open failed.\n");
    else
    {
        if((dfp = fopen(dfile, "wb")) == NULL)
            printf("\aDfile open failed.\n");
        else
        {
            int n;
            while((n = fread(&ch, sizeof(int), 1, sfp)) > 0)
            {
                fwrite(&ch, sizeof(int), 1, dfp);  
            }
             fclose(dfp);  
        }
        fclose(sfp);
    } 
}

 

posted @ 2021-06-10 11:07  小鲨鱼2018  阅读(27)  评论(0编辑  收藏  举报