How to Read Input From File in C Compile
-
03-10-2014 #ane
Registered User
How to input test.txt into c programme?
if i have a plan named prog.c and i take already converted it into an executable using gcc
how practise i examination the prog.o in linux? what is the command for executing a examination file where i have my inputs? so that at ./prog.o what extar command needs to exist added with a examination.txt fiel for inputs?
so if i have to input some numbers and it is supposed to test those inputs and go out on fail?
-
03-x-2014 #two
C++ Witch
That depends on how you are reading input in that plan. For case, if you lot are reading from standard input, then yous could redirect input from the file to the program (or directly enter the test input yourself). If you wrote the program to accept a file name as a control line argument and and then open the file with that proper noun, then you would run the program with the file name equally a command line statement. Or, maybe your program prompts for a file proper name, upon which you would enter the file name equally input when running the programme, so your program opens the file with that name.
Originally Posted by Bjarne Stroustrup (2000-10-xiv)
Look up a C++ Reference and learn How To Ask Questions The Smart Mode
-
03-10-2014 #3
Registered User
yes only what i am trying to do is feed the porgram a txt file with numbers to examination out ,using linux commands
-
03-x-2014 #4
and the hat of int overfl
If your plan reads standard input, and then
./a.out < input.txt
will piece of work.Similarly, you tin save all the output likewise with
./a.out < input.txt > output.txtIf your program accepts arguments, and tries to open a file for say argv[1], then employ
./a.out input.txt
-
03-11-2014 #5
Registered User
Originally Posted by Salem
now i would like to extend the question simply to understand this clearly
if this is my program(hypothetically speaking)
Code:
#include <stdio.h> #include <stdlib.h> int principal(int argc, char * argv[]){ int year; scanf("%d",year); if(year>1528) do_something else return 0; return EXIT_SUCCESS; }
i know i need to include the END OF FILE and too a while loop, but where exactly?
-
03-eleven-2014 #6
and the hat of int overfl
Ignore the fact that yous're reading from a file, how would you notice EOF from the terminal?
Hint: read the manual page for scanf and find out what it returns.
-
03-14-2014 #vii
Registered User
Originally Posted by Salem
and then should i be doing "while(scanf(....);!=EOF);"
-
03-14-2014 #8
Registered User
-
03-fifteen-2014 #9
Registered User
Originally Posted past new2C-
Tim S.
"...a computer is a stupid motorcar with the ability to do incredibly smart things, while reckoner programmers are smart people with the power to practise incredibly stupid things. They are,in short, a perfect match.." Pecker Bryson
Source: https://cboard.cprogramming.com/c-programming/162086-how-input-test-txt-into-c-program.html
0 Response to "How to Read Input From File in C Compile"
Post a Comment