fsetpos() (Set File Position) in C Last Updated : 21 Sep, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The fsetpos() function moves the file position indicator of the given file stream to the specified position. When fsetpos() is executed, the end-of-file indicator is reset. fsetpos() function is a part of <cstdio> header file in C Standard Library. Syntax of fsetpos()int fsetpos(FILE *stream, const fpos_t *pos)Parametersstream - This is the pointer to a FILE object that identifies the stream.position - This is the pointer to a fpos_t object containing the desired value of the position indicator.Return ValueIf it is successful, it returns zero otherwise returns a nonzero value.C Program to Illustrate the use of fsetpos() C // C program to illustrate the use of fsetpos() #include <stdio.h> int main() { // File pointer FILE* fp; // Variable to store file position fpos_t position; // Open file in write and read mode fp = fopen("myfile.txt", "w+"); // Get current file position and store it fgetpos(fp, &position); // Write "HelloWorld!" to the file fputs("HelloWorld!", fp); // Set file position back to the stored position fsetpos(fp, &position); // Write "geeksforgeeks" to the file from the restored // position fputs("geeksforgeeks", fp); // setting file pointer position back to the stored // position fsetpos(fp, &position); // storing data stored in file char arr[50]; fgets(arr, 14, fp); // printing output puts(arr); // Close the file fclose(fp); return (0); } Outputgeeksforgeeks Comment More infoAdvertise with us Next Article C File Pointer S Shivani Ghughtyal Improve Article Tags : Misc C Language C-File Handling Practice Tags : Misc Similar Reads Set Position with seekg() in C++ File Handling seekg() is a function in the iostream library that allows you to seek an arbitrary position in a file. It is included in the <fstream> header file and is defined for istream class. It is used in file handling to sets the position of the next character to be extracted from the input stream from 3 min read C File Pointer A file pointer is a variable that is used to refer to an opened file in a C program. The file pointer is actually a structure that stores the file data such as the file name, its location, mode, and the current position in the file. It is used in almost all the file operations in C such as opening, 3 min read C Program to find size of a File Given a text file, find its size in bytes. Examples: Input : file_name = "a.txt" Let "a.txt" contains "geeks" Output : 6 Bytes There are 5 bytes for 5 characters then an extra byte for end of file. Input : file_name = "a.txt" Let "a.txt" contains "geeks for geeks" Output : 16 Bytes The idea is to us 1 min read C Program to find size of a File Given a text file, find its size in bytes. Examples: Input : file_name = "a.txt" Let "a.txt" contains "geeks" Output : 6 Bytes There are 5 bytes for 5 characters then an extra byte for end of file. Input : file_name = "a.txt" Let "a.txt" contains "geeks for geeks" Output : 16 Bytes The idea is to us 1 min read fseek() vs rewind() in C In C, the functions fseek() and rewind() helps in manipulating the position of the pointer in the opened file but serve different purposes and have distinct working. The below table lists the major differences between fseek() and rewind() in C:Featurefseek()rewind()FunctionalityMoves the file pointe 2 min read fclose() Function in C In C language, fclose() is a standard library function used to close a file that was previously opened using fopen(). This function is the itegral part of the file handling in C which allows the users to free the memory occupied by the file once all the operations are done on it.In this article, we 2 min read Like