I have a function getNum(), which gets a number from file and returns it. When I go back into getNum() I have lost the pointer and it starts at the begging of the file again. I'm wondering How do I get the location of where getc is and then go back to that place. I couldn't find how to do this in the manual or in forums. Thank you.
#include <stdio.h>
#include <stdlib.h>
int getNum();
int getLine();
int getMatrix();
main() {
int num;
int two;
num = getNum();
printf("%d\n", num);
two = getNum();
printf("%d\n", two);
}
int getNum() {
FILE *infile;
infile = fopen("matrix.txt","r");
int c;
double value = 0;
while ((c=getc(infile)) != '\n') {
if(c==32){
if(value != 0){
return(value);
}
//otherwise keep getting characters
}
else if ((c<=47)||(c>=58)){
printf("incorrect number input %d\n", c);
exit(1);
}
else {
value = (10*value) + c - '0';
}
}
return(value);
}