Accessing int at end of file
Hi, I'm learning to use files in C and I was wondering how to access an integer at the end of a text file.
The file has some strings before, and the last line should be:
Output=6
I'd like to make a function that stores that 6 in a variable and returns it.
I've managed to store integers when the file is made just out of numbers, eg:
Code:
FILE *pf;
int i;
int input[]={25,1,2,5,4};
int output;
char pepe[20]="pepe";
pf=fopen("test.txt","w");
for(i=0;i<5;i++)
fprintf(pf,"%d\n",input[i]);
fclose(pf);
pf=fopen("test.txt","r");
while(fscanf(pf,"%d",&output)!=EOF)
printf("Output: %d\n",output);
fclose(pf);
But not when there are strings throughout the file.
Any help?
thanks!