I’m trying to write a function which reads a file name (par.dat) and prints to screen a value written into the file. This value can be an integer such as 12. However, my code is prints to screen only “0” value. Can someone show me how to fix this?
#include<stdio.h>
#include<stdlib.h>
int foo( const char *argv){
FILE *fp;
char c[25];
FILE *fptr;
fptr = fopen(argv, "r");
fscanf(fptr,"%[^\n]", c);
fp = fopen(c, "r");
fscanf(fp, "%d", &num);
printf("%d\n", num);
fclose(fptr);
}
int main(){
int num;
foo("par1.dat");
return 0;
}