C语言学习(40)

 1 //rewind函数的作用是使位置指针重新返回指定文件的开头
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 int main(){
 5     FILE *fp;
 6     char s[]="abcdefghijklmnopqrstuvwxyz";
 7     char c;
 8     if((fp=fopen("file_data.txt","w+"))==NULL){
 9         printf("打开文件失败\n");
10         exit(0);
11     }
12     fprintf(fp,"%s",s);
13     rewind(fp);
14     fscanf(fp,"%c",&c);
15     printf("第一个字符为:%c\n",c);
16     fclose(fp);
17     return 0;
18 }
 1 //rewind函数的作用是使位置指针重新返回指定文件的开头
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 int main(){
 5     FILE *fp;
 6     char s[]="abcdefghijklmnopqrstuvwxyz";
 7     char c;
 8     if((fp=fopen("file_data.txt","w+"))==NULL){
 9         printf("打开文件失败\n");
10         exit(0);
11     }
12     fprintf(fp,"%s",s);
13     rewind(fp);
14     fscanf(fp,"%c",&c);
15     printf("第一个字符为:%c\n",c);
16     fclose(fp);
17     return 0;
18 }

猜你喜欢

转载自www.cnblogs.com/Tobi/p/9239920.html
今日推荐