Switch to full style
For C/C++ coders discussions and solutions
Post a reply

getting a full line input

Sat Nov 08, 2008 10:55 pm

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.



Re: getting a full line input

Sat Nov 08, 2008 10:56 pm

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).

Post a reply
  Related Posts  to : getting a full line input
 Reading a File Line by Line in php     -  
 full Screen Graphics     -  
 Full Encription System (DES-AES,RSA and more)     -  
 Full scrollable table     -  
 Full Screen graphics (Lesson 2).     -  
 Full Phone Book System php and mysql     -  
 How to show full resolution image at clicking on thumnail     -  
 Java Websphere Portal Developer Full-time position in IL     -  
 Only numeric input in JTextField     -  
 input suggestion using Javascript     -  

Topic Tags

C++ Files and I/O