So, I'm rather new to reading and writing files. I have the following program:
I also have a file named num.dat that contains a single number, 100. However, the printf only prints 0 as the read number. What am I doing wrong?Code:#include <stdio.h> int main() { int number; FILE *num; num=fopen("file directory\num.dat","r"); fscanf(num,"%d",&number); printf("Read number: %d\n",number); fclose(num); return 0; }
EDIT: Obviously, "file directory" in the above code is the actual file directory in my pc.
EDIT2: Problem solved, I needed to add double backslashes. Thanks everyone