How to use rewind() function to set the position of file pointer to the beginning of the file in C

1 Answer

0 votes
#include <stdio.h>
   
int main(void)
{
	char buf[27];

	FILE *fp = fopen ("d:\\data.txt","w+");
	for (char ch = 'A' ; ch <= 'Z' ; ch++)
		fputc(ch, fp);
		
	rewind(fp);
  
	fread(buf, 1, 26, fp);
	fclose(fp);
  
	buf[26]='\0';
	puts(buf);
	
    return 0;
}
  
/*
run:
  
ABCDEFGHIJKLMNOPQRSTUVWXYZ

*/

 



answered May 6, 2016 by avibootz

Related questions

1 answer 216 views
1 answer 85 views
2 answers 183 views
1 answer 107 views
...