C 从不兼容的指针类型传递fwrite的参数4

C 从不兼容的指针类型传递fwrite的参数4,c,fwrite,gcc-warning,C,Fwrite,Gcc Warning,我想将源文件的内容复制到目标文件,但收到以下警告: 警告:从不兼容的指针类型[-Wincompatible指针类型]传递'fwrite'的参数4 fwrite(target,sizeof(char),targetSize,sourceContent); 如果忽略警告,则会出现分段错误 FILE *source = fopen(argv[1], "r"); FILE *target = fopen(argv[2], "w"); if (source == NULL || target == N

我想将源文件的内容复制到目标文件,但收到以下警告:

警告:从不兼容的指针类型[-Wincompatible指针类型]传递'fwrite'的参数4
fwrite(target,sizeof(char),targetSize,sourceContent);
如果忽略警告,则会出现分段错误

FILE *source = fopen(argv[1], "r");
FILE *target = fopen(argv[2], "w");

if (source == NULL || target == NULL) {
    printf("One or both files do NOT exist\n");
    abort();
}

fseek(source, 0, SEEK_END);
long sourceSize = ftell(source);

fseek(source, 0, SEEK_SET);
char *sourceContent = (char *)malloc(sourceSize);
fread(sourceContent, sizeof(char), sourceSize, source);


long targetSize = sourceSize;
fwrite(target, sizeof(char), targetSize, sourceContent);
两者都将读/写缓冲区作为第一个参数,将文件作为第四个参数

// This is fine.
fread(sourceContent, sizeof(char), sourceSize, source);
// Swap the first and fourth argument in the fwrite call.
fwrite(sourceContent, sizeof(char), targetSize, target);