Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Redirecting Standard Input C (http://www.go4expert.com/forums/redirecting-standard-input-c-t2760/)

Chrystian_Vieyra 30Jan2007 09:31

Redirecting Standard Input C
I am trying to redirect standard input to be a file, unfortunately I have not been succesful.

My command in unix to execute my c applicacion is:

a.out < file.something

However, I receive a segmentation error.

my c code to read that standard in is here:

void input()
 char s[1];
 printf("Contents %c", s[1]);

pradeep 30Jan2007 11:08

Re: Redirecting Standard Input C
Try reading this http://www.cs.odu.edu/~zeil/cs361/Le...nterCrash.html

shabbir 30Jan2007 14:40

Re: Redirecting Standard Input C
The segmentation error is you are defining the size of the array as 1 and you are doing the scanf in the position 1 but it should be at 0. Also you need to specify the address of the variable and not the variable.



Also you now know what you need to be doing with printf I guess.

DaWei 30Jan2007 17:21

Re: Redirecting Standard Input C
What's the point of a one-byte array? Why not just define a char? You also might as well redirect a line at a time since the standard libraries don't fetch a character at a time. They don't give you anything until the end of the line is encountered. You have to go implementation-specific for keystroke-level input.

All times are GMT +5.5. The time now is 13:56.