Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - C language fwrite needs two forms to write the integer array into a file, such as writing the whole array into a file or writing one by one, which needs to pass the test.
C language fwrite needs two forms to write the integer array into a file, such as writing the whole array into a file or writing one by one, which needs to pass the test.
# include & ltstdio.h & gt

# include & ltstdlib.h & gt

# include & lttime.h & gt

int? Master ()

{

int? Me;

int? Data [10];

Documents? *fp 1,* fp2

if((FP 1 = fopen(" data 1 . 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(& amp; data[i],sizeof(int), 1,FP 1); //Write one by one

}

fwrite(data,sizeof(int), 10,fp2); //written in a block

printf(" \ n ");

fclose(FP 1);

fclose(fp2);

Return? 0;

}