//file function re-speak//fseek (), Ftell (),#define_crt_secure_no_warnings#include<stdio.h>#include<stdlib.h>voidMain () {//Defining file Paths Char*path ="E:\\look\\b1.txt";//Support window only Char*path1 ="E:/look/b1.txt";//support Windows and Linux//Defining file PointersFILE *PF =NULL; //open a file as read-writePF = fopen (path1,"r+"); //determine if the file is open successfully if(pf==NULL) {printf ("File open failed! File path is%s\n", path1); } //int fseek (FILE *stream, long offset, int origin); //the first parameter stream is a file pointer//The second parameter offset is offset, positive number indicates positive offset, negative is negative offset//The third parameter, origin, sets the offset from where the file begins, possibly with a value of: Seek_cur, Seek_end, or Seek_set//seek_set: File Start//seek_cur: Current Location//seek_end: End of File//among them Seek_set, Seek_cur and Seek_end are 0, 1 and 2 in turn. //In short://fseek (FP, 100L, 0); Move the stream pointer to 100 bytes from the beginning of the file;//fseek (FP, 100L, 1); Move the stream pointer to 100 bytes from the current position of the file;//fseek (FP, -100l, 2); Returns the stream pointer to 100 bytes from the end of the file. Charbuf[ -] = {0}; Fgets (BUF, -, PF); printf ("Output result%s\n", BUF); //move the file pointer to the end of the fileFseek (PF,0L, Seek_end); //calculates the file pointer offset (essentially the size of the file) intnum =Ftell (PF); //function Name: Ftell//function prototype: Long Ftell (FILE *stream); //function function//The number of offset bytes used to get the current position of the file position pointer relative to the top of the file. (using the Fseek function and then calling the function Ftell () makes it very easy to determine the current position of the file.) )//constraint conditions//because Ftell returns a long type, there is an error in manipulating files larger than 2.1G, depending on the range of long values-231~231-1 (-2147483648~2147483647). printf"file size%d bytes \ n", num); //Close File if(pf!=NULL) {fclose (PF); } System ("Pause");}
C-Language file operations 11--file functions re-speak fseek () and Ftell ()