码迷,mamicode.com
首页 > 其他好文 > 详细

19.05.02--读写文件

时间:2019-05-02 11:51:27      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:signed   txt   turn   std   char   for   open   --   eof   

#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;
}

19.05.02--读写文件

标签:signed   txt   turn   std   char   for   open   --   eof   

原文地址:https://www.cnblogs.com/redyellowblue/p/10801821.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!