Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset scanf()

Tags:

c

scanf

How do you reset scanf() to read the beginning of the text without the use of fopen or fclose.

I have a stage 1 which reads half of the text file and stage 2 requires me reset the scanf() to beginning of the text and read it all the way. Any tips or guidance is appreciated. You Guys are the best!

EDIT: The text has ONLY numbers in it and the file is opened via /myprogram <txt.txt.

like image 903
hellowurf Avatar asked Dec 08 '25 06:12

hellowurf


2 Answers

You can use fseek() or rewind().

rewind(fp);

or

fseek(fp, 0, SEEK_SET);
like image 68
Chan Avatar answered Dec 10 '25 20:12

Chan


One can use rewind(FILE *fp) to reset the position to beginning of the file.

like image 38
Prabhu Avatar answered Dec 10 '25 20:12

Prabhu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!