M
mario.demiguel
Hello all, I believe I know the basics of what I need to do, but some
clarification would help.
I want to open a text file using functions from stdio.h. Then I want
to output the text in this file to the screen. This is meant to be
part of a Windows console app.
Currently, I have the following, which works but has problems:
#include <stdio.h>
int main(int argc, char *argv[])
{
const char mode[1]={'r'};
FILE * test;
char str [sizeof(test)];
test = fopen("C:\\test.txt", mode);
fread(str,sizeof(str[0]),50,test);
/*I need to find a better way to come up with the value. 50 is
just a magic number that happens to work. 200 for instance wouldn't*/
printf(str);
}
Is there a better way to do this? Also, when is it appropriate to use
fscanf instead of freadf? Thanks in advance.
clarification would help.
I want to open a text file using functions from stdio.h. Then I want
to output the text in this file to the screen. This is meant to be
part of a Windows console app.
Currently, I have the following, which works but has problems:
#include <stdio.h>
int main(int argc, char *argv[])
{
const char mode[1]={'r'};
FILE * test;
char str [sizeof(test)];
test = fopen("C:\\test.txt", mode);
fread(str,sizeof(str[0]),50,test);
/*I need to find a better way to come up with the value. 50 is
just a magic number that happens to work. 200 for instance wouldn't*/
printf(str);
}
Is there a better way to do this? Also, when is it appropriate to use
fscanf instead of freadf? Thanks in advance.