fread fwrite 简单问题
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE * FPFROM, *FPTO;
char p;
if ((FPFROM = fopen("file.in" ,"rb")) == NULL)
{
printf("errow open read\n");
exit(0);
}
if ((FPTO = fopen ("file.out", "w+b")) == NULL)
{
printf("errow open read\n");
exit(0);
}
while (fread(&p,1,1, FPFROM))
fwrite(&p,1,1, FPTO);
fclose(FPTO);
fclose(FPFROM);
printf("Hello, world!\n");
return EXIT_SUCCESS;
}
这样的代码 没有问题的
但是如果 我想节省fread 的次数
用char p[1024];
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE * FPFROM, *FPTO;
char p[1024];
if ((FPFROM = fopen("file.in" ,"rb")) == NULL)
{
printf("errow open read\n");
exit(0);
}
if ((FPTO = fopen ("file.out", "w+b")) == NULL)
{
printf("errow open read\n");
exit(0);
}
while (fread(p,1024,1, FPFROM))
fwrite(p,1,124, FPTO);
fclose(FPTO);
fclose(FPFROM);
printf("Hello, world!\n");
return EXIT_SUCCESS;
}
会有错 应该怎么做呢?

