#include
#include
#include
int main()
{
int i;
int data[10];
FILE *fp1,*fp2;
if((fp1=fopen("data1.dat","at+"))==NULL)
{
printf("ERROR!!!\n");
return 1;
}
if((fp2=fopen("data2.dat","at+"))==NULL)
{
printf("ERROR!!!\n");
return 1;
}
srand(time(NULL));
for(i=0;i<10;i++)
{
data[i]=rand()%100;
printf("%-5d",data[i]);
fwrite(&data[i],sizeof(int),1,fp1);//逐个写入
}
fwrite(data,sizeof(int),10,fp2);//一块写入
printf("\n");
fclose(fp1);
fclose(fp2);
return 0;
}