作为刚刚大一的我,请教各位大佬(手动舔🐕):
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
int x[1000], i, k;
FILE *fp2;
srand((unsigned)time(NULL));
for (i = 0; i < 1000; i++)
x[i] = rand();
fp2 = fopen("C:\\Users\\lei\\Desktop\\data.dat", "wb");
if (fp2 == NULL)
{
printf("Open error\n"); exit(0);
}
for (k = 0; k < 1000; k++) fwrite(&x[k], sizeof(int),1,fp2);//(1)这句中&x[k]的位置不应该使数组的首地址&x[0]吗?
fclose(fp2); (2)可以换成fwrite(&x[0],sizeof(int),1,fp2)吗?
}