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);
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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..
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..
ASKER
kewl, thanks for the explanation.
welcome
not just any other .. any other >= 2