Reading integers from a file in C

cfilescanf

I've been struggling with this for a really long time trying to figure it out, I'm guessing it's a really stupid noob mistake but I can't figure it out.

So I'm trying to read in an integer from a file and then do some operations in it, for the sake of the problem I'm just trying to output it here:

FILE * pFile;
int number;
pFile = fopen ("myfile.txt","r");
if (pFile!=NULL) {
fscanf(pFile, "%d", number);
fclose (pFile);
}
printf("number: %i", number);
return 0;

the contents of myfile.txt:

123

but when I run it it doesnt read it anything instead it says

RUN FAILED (exit value 1, total time: 32ms)

Thanks for any and all help

EDIT: I forgot to mention, it works as a string, it reads the correct number, but I can't do any operations on it, also if I set the number type to double it works but outputs some random number in the millions…

Best Answer

You need to pass the address of the int variable to fscanf

fscanf(pFile, "%d", &number);