C语言学习(41)

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

 

posted on 2018-06-28 17:43  孙悟空son_ku_kong  阅读(148)  评论(0编辑  收藏  举报

导航