View Full Version : how can i read file on standard input using scanf?
well i'm totally new to C... how can i read file on standard input using the scanf fuction? thanks
maharg
06-08-2004, 04:29 AM
Um... are you asking how to use scanf? Because scanf always reads from stdin.
no i mean.. if i give it a file, say text.txt... how can i read the contents of that file?
hmmm... nevermind.. i think i misunderstood what was being asked...
maharg
06-08-2004, 04:33 AM
Run it like this:
myprog < file.txt
If you want your program to open the file, use fopen() to open it, then use fscanf instead of scanf.
Lathentar
06-08-2004, 04:50 AM
Or you could use C++ and use streams.
maharg
06-08-2004, 05:10 AM
Or you could use C++ and use streams.
In all my years of helping people with this sort of stuff I've learned it's generally best to let people burn their hands on the ring.
Lathentar
06-08-2004, 05:16 AM
In all my years of helping people with this sort of stuff I've learned it's generally best to let people burn their hands on the ring.
It took a generics programming class for me to realize the true power of streams. Might as well get him started on the right foot, its really easy to get attached to scanf/printf.
it's a C course... i can't use anything but C :(
vBulletin v3.0.3, Copyright ©2000-2004, Jelsoft Enterprises Ltd.