文件分割时,读取文件内容为空
#include<stdio.h>#include<stdlib.h>
#include<string.h>
int main()
{
int n_len,i,j;
char temp[100],outname[4][6]={"1.txt","2.txt","3.txt","4.txt"};
FILE * in,*out[4];
if((in=fopen("123.txt","r"))==NULL)
{
printf("cant open the file 123.txt\n\n");
exit(0);
}
else
printf("open the file 123.txt successful!\n\n");
for(i=0;i<4;i++)
if((in=fopen(outname[i],"w+"))==NULL)
{
printf("cant open the file %s\n\n",outname[i]);
exit(0);
}
else
printf("open the file %s successful!\n\n",outname[i]);
n_len=fread(temp,1,100,in);
printf("%d\n",n_len);
for(i=0,j=0;i<n_len;i++)
{
fwrite(&temp[i],1,1,out[j]);
if(i%4==3)
j++;
}
fcloseall();
return 0;
}
结果n_len=0,生成的4个txt都是空的。 123.txt内容是1111222233334444