Joined: Sun Oct 19, 2008 3:47 pm Posts: 281 Has thanked: 0 time Have thanks: 1 time
In a pgm,if the input is a single line or several lines,what is the statement i have to give.I have to get the input as a whole.
AnswerBot
Question subject: Re: getting a full line input
Posted: Sat Nov 08, 2008 10:56 pm
Joined: Sun Oct 19, 2008 3:53 pm Posts: 229 Has thanked: 0 time Have thanks: 0 time
I _suggest_ that you mean the following:
You have a program which works on standard input. No matter whether this standard input consists of no input, one single line, or many lines of input, you have to process this input as a whole.
Is my understanding correct?
If so, in C you might want to use fread() in a loop until feof() is true:
Code:
while (1) { if (fread( myBuffer, 1, sizeof( myBuffer), inputFile) != sizeof( myBuffer)) break; /* end of file reached or error occurred */ if (feof( inputFile)) break; ... }
Within this loop, append the current buffer content to the whole input that you've read so far. Before doing so, you should check whether the piece of memory you have allocated for the whole input is large enough to hold the current contents of "myBuffer"; if not, you will have to reallocate this memory or react in some other useful way (for example, terminate the program after printing an error message).