Showing posts with label fsetpos() function program in c. Show all posts
Showing posts with label fsetpos() function program in c. Show all posts

Saturday, October 24, 2020

, ,

Example program for fsetpos() function in C programming

 In c handling, fsetpos() function will be used to set the position of input file with the help of fsetpos() access that point.

If you use to fix the file indicator position at any time in the given file then we need to use the fsetpos() function.

 Return Value :- fsetpos() function return zero at the time of success or non zero at failure. 

Example program for fsetpos()
Example program for fsetpos() function in C programming

 

Example program for fsetpos() function

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

int main(){
	
	FILE *f;
	
	char ch[100];
	
	fpos_t pos;

	
	f=fopen("functioninc.txt","w+");
	
	fgetpos(f,&pos);
	printf("Enter any five strings\n");
	for(int i=0;i<4;i++){
		
		scanf("%[^\n]",&ch);
		//write back to the file
		fputs(ch,f);
		
		fputs("\n",f);
		
		fflush(stdin);
	}
	//take the strings from the users
	scanf("%[^\n]",&ch);
	fputs(ch,f);
	
	fsetpos(f,&pos);
	printf("\n...............print the strings..............\n\n");
	while(!feof(f)){
		
		fgets(ch,100,f);
		
		printf("%s",ch);
	}

	//close the file
	fclose(f);

	return 0;
}<4 0="" 100="" a="" after="" and="" array="" back="" buffer="" ch="" character="" clear="" close="" don="" entry.otherwise="" entry="" every="" except="" f="" fclose="" feof="" fflush="" fgets="" file="" first="" for="" fputs="" from="" fsetpos="" i="" if="" in="" indicator="" initial="" is="" last="" line="" n...............print="" n="" new="" of="" or="" pos="" position="" pre="" print="" printf="" return="" s="" scanf="" set="" space="" stdin="" stream="" string="" strings..............="" strings="" t="" take="" takes="" taking="" the="" then="" this="" time="" to="" twice="" users="" waiting="" we="" while="" white="" write="">