这个程序说得是
1。建立一个文件,随即选择100个数,然后读取
2,可以选择性的访问
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (void)
{
int seed,i,a,b[99];
int *k;
FILE *p;
char fname[]="hii.bin";
seed=time(NULL);
srand(seed);
if((p=fopen(fname,"w"))==NULL){
printf("can't open it \n");
exit(1);
};
for(i=0;i<100;i++){
a=rand()%101;
fwrite(&a,sizeof(int),1,p);
}
fclose(p);
if((p=fopen(fname,"r"))==NULL){
printf("can't open it \n");
exit(1);
};
fread(&b[0],sizeof(int),100,p);
for(i=0;i<100;i++)
printf("%d\n",b[i]);
fclose(p);
if((p=fopen(fname,"r"))==NULL){
printf("can't open it \n");
exit(1);
};
printf("Input the number which you wanna see\n");
scanf("%d",i);
rewind(p);
fseek(p,i*4L,0);
fread( k,4,1,p);
printf("%d",k);
fclose(p);
return 0;
}
在编译器里面检验是无错的 不过就是有时候显示不出来数字 还有选择性的访问也不行
请指点一下