fseek
fseek.c
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main(void) 5 { 6 // 打开/创建 7 FILE *fp = fopen("./1.text","w+"); 8 if(fp==NULL){ 9 perror("fopen failed"); 10 exit(1); 11 } 12 13 // 写字符串 14 fputs("panda_w " , FP); 15 16 . 17 // File Location 18 is fseek (FP, 2 , SEEK_SET); // the beginning of the file stream position is set, and the two move! . 19 20 is 21 is // reading character 22 is int P = fgetc ( FP); 23 is IF (P == the EOF) { 24 perror ( " fgetc failed " ); 25 Exit ( . 1 ); 26 is } 27 the printf ( " Read: C% \ n- " , P); 28 29 30 // Close 31 is fclose (FP); 32 33 is return 0 ; 34 is }
test:
success !