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 }

猜你喜欢

转载自www.cnblogs.com/Tobi/p/9239924.html