What am i missing in this code?
char a;
FILE *myfile;
myfile = fopen("jump.txt", "r");
a = "jump.txt";
fscanf(myfile, &a);
printf(" %s", a);
}
What am i missing in this code?
char a;
FILE *myfile;
myfile = fopen("jump.txt", "r");
a = "jump.txt";
fscanf(myfile, &a);
printf(" %s", a);
}
Lots of things. Maybe you'd better explain what you're actually trying to do, before we go telling you where you're going wrong.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
I created the text file "jump.txt and i want C to read the information in the .txt file, then put the output onto the screen.
/* this will read the text file: jump.txt*\
/* and will put it on the output screen *\
char a;
FILE *myfile;
myfile = fopen("jump.txt", "r");
a = "jump.txt";
fscanf(myfile, &a);
printf(" %s", a);
}
OK, I see.
- I wouldn't use fscanf() to do this. Try looking up fgetc() to get one character at a time.
- a="jump.txt" is incorrect. a is only a char, and can therefore hold only 1 letter. You don't need this line anyway.
- printf() with %s is for strings, again, a is only a single char, so it won't work.
Pseudo code for you to follow:
There's some examples here. They're not showing this specific use, but you should be able to gain something from reading them. (look at the last example on that page)Code:- Open file - Validate its open correctly - While Read one character is not EOF - DO - putchar() - END DO - close file
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Also, the correct way to do comments is with /* ... */
-Govtcheez
[email protected]