I\'m trying to start simple with understanding file i/o but I can\'treally see w
ID: 3617432 • Letter: I
Question
I'm trying to start simple with understanding file i/o but I can'treally see where I'm going wrong with this program.I made a file called "bogus.txt" and all I typed was thenumber 7. I'm trying to open the file, read the number, andprint it on the screen.
I cant do it.
I get some number like 2203357 or something.
#include <stdio.h>
int main(void) { FILE* fin; int numberOf, total = 0, i; fin = fopen("bogus.txt", "r"); fscanf(fin, "%d", &numberOf); total = numberOf; printf("%d", total); fclose(fin); getch(); system("PAUSE"); return 0; }
Please tell me what I am doing wrong...
I made a file called "bogus.txt" and all I typed was thenumber 7. I'm trying to open the file, read the number, andprint it on the screen.
I cant do it.
I get some number like 2203357 or something.
#include <stdio.h>
int main(void) { FILE* fin; int numberOf, total = 0, i; fin = fopen("bogus.txt", "r"); fscanf(fin, "%d", &numberOf); total = numberOf; printf("%d", total); fclose(fin); getch(); system("PAUSE"); return 0; }
Please tell me what I am doing wrong... #include <stdio.h>
int main(void) { FILE* fin; int numberOf, total = 0, i; fin = fopen("bogus.txt", "r"); fscanf(fin, "%d", &numberOf); total = numberOf; printf("%d", total); fclose(fin); getch(); system("PAUSE"); return 0; }
Please tell me what I am doing wrong...
Explanation / Answer
please rate - thanks there is nothing wrong with your code. I ran it, it works perfectly did you create the bogus.txt file correctly open notepad type 7 enter save the file you must type the enter or you will have problems