Link to home
Start Free TrialLog in
Avatar of harliquen
harliquen

asked on

displaying piped input

Basically I am trying to get a program to redisplay the contents of the file that is piped into it, unfortunately it only accepts input up to the newline character, and I can't figure out how to get the other lines to display.

eg. when the following program is run by executing: "program < filetodisplay.txt" it will only show the first line. How do I get it to display all the lines? Thanks!
 
main () {
 char *string;
 scanf("%s", string);
 printf("%s", string);
}
ASKER CERTIFIED SOLUTION
Avatar of akshayxx
akshayxx
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>#define BUFSIZE 256  //any other value u comfortable with

not just any other .. any other >= 2
Avatar of harliquen
harliquen

ASKER

Thanks! but what happens if you don't know how large the input file is going to be? ie. what if it is larger than the BUFSIZE you specify? how can you make it adjust accordingly?

in my example if u are concerned with only reading and displaying the file .. the buffer size doesnt matter.. ( shud be greater than 2)

as by definition of gets and fgets .. it reads only that much characters that will fit in the size of buffer ( minus one space for NULL string terminitator)..
and i keep reading in while loop .. till i can read anyting ( which is till end of file occurs)

hence no problems here..
kewl, thanks for the explanation.
welcome