-
input files in C
This is a simple question, but I don't use C often. I have a program which takes data from an input file, but I need to use C input funtions. I can either 1) redirect input at the command line (a.out < data.txt) or 2) have the user specity an input file at runtime.
I am currently using the first option, but my problem is that I use getch() to accept keyboard input later in the program. I do not know how to "unredirect" the input from the data file to the keyboard. I would actually like to use the 2nd option, but the only method I know to take input from a file is ifstream. I CANNOT use that. Can somebody help me out here?
-
>>I would actually like to use the 2nd option
Lookup the C I/O functions:
- fopen()
- fgets()
- fclose()
and more.
-
Thanks alot
I'm really glad I found this board...I was getting discouraged.
-
>>I was getting discouraged.
Dispair no more... we're here to help ;) If there's something you don't know/understand, take a good look round here (faqs, tutorials, use the search forums button etc). If you can't find your answer, post a message and someone will help you.
Happy coding. :)
-
dont worry!!!
hi folk,
use the second option and here is the code for , only
if u did
not know
about it.....
int main(int argc,char **argv)
{
FILE *fp;
fp = fopen("your input file name", "r+");
{
/ /u'r input file content is stored in file pointer fp
//continue with what u want to do
}
fclose(fp);
}