合并2个二进制文件。文件之间的残留数据

时间:2016-04-10 19:26:19

标签: c file merge binary concatenation

我的任务是合并多个二进制文件,然后把它们全部放在一个txt文件中,我已经有了文件的格式,我已经编写了它们,但是我合并它们失败了。这是功能: Output from the binary file into the txt file.

int merge_files()
{
    FILE *f1, *ft;
    char ch, name1[20];
    int  error, n;
    char buffer[10000];
    printf("\n Give name of file: "); gets_s(name1, 19);
    while (strlen(name1) != NULL)
    {
        fopen_s(&f1, name1, "rb");
        fopen_s(&ft, "finaldata.dat", "a");
        if (!f1)
        {
            error = 1;
            break;
        }
        else
        {
            error = 0;

            rewind(f1);

            while (n = fread(buffer, sizeof(char), 10000, f1))
            {
                fwrite(buffer, sizeof(char), n, ft);
                fflush(ft);
            }
        }

        fclose(f1);
        fclose(ft);
        printf("Files had been merged");
        printf("\n Give name of file: "); gets_s(name1, 19);
    }

    return error;
}

0 个答案:

没有答案