19.05.02--读写文件

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
int main()
{
 int j=0,x,a[1024];
 char rand_num[5];
 FILE *stream=fopen("1.txt","w");
 srand((unsigned)time(NULL));
 for(int i=0;i<500;i++)
 {
  x=rand()%100;
  sprintf(rand_num,"%d\n",x);
  fputs(rand_num,stream);
 }
 fclose(stream);
 stream=fopen("1.txt","r");
 i=0;
 while(!feof(stream))fscanf(stream,"%d",&a[i++]);
 for(i=0;i<500;i++)printf("%d\t",a[i]);
 printf("\n");
 fclose(stream);
 return 0;
}
posted @ 2019-05-02 11:00  拓荒的路上  阅读(106)  评论(0编辑  收藏  举报