rewind() function in c

Previous
Next

rewind():

  • Reset the cursor position to start of the file.
  • Prototype is :
    • void  rewind(FILE* stream);
#include<stdio.h>
int main()
{
	FILE* p;
	int ch;	
	p = fopen("code.c", "r");
	if(p==NULL)
	{
		printf("No such file to open \n");
	}
	else
	{
		fseek(p, -50, SEEK_END);
		while((ch=fgetc(p)) != -1)
		{
			printf("%c", ch);	
		}
		
		rewind(p);
		while((ch=fgetc(p)) != -1)
		{
			printf("%c", ch);	
		}
		fclose(p);
	}
	return 0;
}
Previous
Next

Add Comment

Courses Enquiry Form