fseek() is used to move file pointer associated with a given file to a specific position.
int fseek(FILE *pointer, long int offset, int position) pointer: pointer to a FILE object that identifies the stream. offset: number of bytes to offset from position position: position from where offset is added. returns: zero if successful, or else it returns a non-zero value
position defines the point with respect to which the file pointer needs to be moved. It has three values:
SEEK_END : It denotes end of the file.
SEEK_SET : It denotes starting of the file.
SEEK_CUR : It denotes file pointer’s current position.
The file test.txt contains the following text:
"Someone over there is calling you. we are going for work. take care of yourself."
When we implement fseek() we move the pointer by 0 distance with respect to end of file i.e pointer now points to end of the file. Therefore the output is 81.
Related article: fseek vs rewind in C
This article is contributed by Hardik Gaur. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- fseek() vs rewind() in C
- Function Interposition in C with an example of user defined malloc()
- Buffer Overflow Attack with Example
- Format String Vulnerability and Prevention with Example
- Named Pipe or FIFO with example C program
- ftell() in C with example
- Writing first C++ program : Hello World example
- std::search_n with example in C++
- pthread_self() in C with Example
- pthread_cancel() in C with example
- pthread_equal() in C with example
- tellp() in file handling with c++ with example
- Command line arguments example in C
- vector::crend() & vector::crbegin() with example
- asin() and atan() functions in C/C++ with Example
- tellg() function in C++ with example
- wcstok() function in C++ with example
- wcsstr() function in C++ with example
- wcsncpy() function in C++ with example
- forward_list::cend() in C++ STL with Example