C读取文件

 1 #include<stdio.h>
 2 int main(){
 3   FILE *fp;
 4   int data,max,min;  
 5   fp=fopen("data.txt","r");//假定文件名为data.txt
 6   fscanf(fp,"%d",&max);
 7   min=max;
 8   while(!feof(fp)){
 9     fscanf(fp,"%d",&data);
10     if(max<data)max=data;
11     if(min>data)min=data;
12   }
13   printf("max=%d\n",max);
14   printf("min=%d\n",min);
15   return 0;
16 }
txt:
43 56

 

posted @ 2014-01-01 15:18  yuanqi  阅读(138)  评论(0编辑  收藏  举报