Home » C programs » stdio.h header file functions

fsetpos() function in C language with Example

Here, we are going to learn about the fsetpos() function of library header stdio.h in C language with its syntax, example.
Submitted by Souvik Saha, on January 24, 2019

fsetpos() function in C


    int fsetpos(FILE* filename, fpos_t *position);


    FILE* filename, fpos_t *position

Return type: int

Use of function:

In file handling, through the fsetpos() function we set the position of the input file stream indicator at the point which we get from fgetpos(). Whenever we need to fix the file indicator position in the file, we need to use the function fgetpos(). The prototype of the fgetpos() function is:

    int fsetpos(FILE* filename, fpos_t *position);

Here, the data type of the position variable must be fpos_t type. A return value of zero means the successful operation and non-zero returns means failure.

fsetpos() example in C

#include <stdio.h>
#include <stdlib.h>

int main(){
	//Initialize the file pointer
	FILE *f;
	//Take a array of characters 
	char ch[100];
	//Initialize the position variable 
	fpos_t pos;

	//Create the file for write operation
	//Store the value of the function point indicator
	printf("Enter five strings\n");
	for(int i=0;i<4;i++){
		//take the strings from the users
		//write back to the file
		//every time take a new line for the new entry string 
		//except for last entry.Otherwise print the last line twice
		//clear the stdin stream buffer
		//if we don't write this then after taking string 
		//%[^\n] is waiting for the '\n' or white space
	//take the strings from the users
	//set the indicator position to the initial position of the file
	printf("\n...............print the strings..............\n\n");
		//takes the first 100 character in the character array 
		//and print the strings

	//close the file

	return 0;


fsetpos example in c

Comments and Discussions

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.