just a Q

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
ywceric
New poster
Posts: 5
Joined: Fri Jan 07, 2005 12:58 pm

just a Q

Post by ywceric »

as u see, the input method of most of the task are in many lines.
how can i know when the input ends?
Cahoun
New poster
Posts: 13
Joined: Mon Jan 03, 2005 2:34 pm
Location: Czech Republic
Contact:

Re: just a Q

Post by Cahoun »

ywceric wrote:as u see, the input method of most of the task are in many lines.
how can i know when the input ends?
Most of problems have end of input in specification. Very often is end of file as number 0(zero) or end of file. You have to check and control end of input in your program.
Learn, learn, learn.
neowarez
New poster
Posts: 14
Joined: Tue May 06, 2003 11:04 pm
Location: Portugal
Contact:

..

Post by neowarez »

well..

if you have a number of test cases.. you just do a for cycle.. if your task is to read until end of file just control EOF (end of file).

For example scanf returns the number of arguments read if the value returned is 0 then input ends.

gets function is almost like that.. if 0 is returned then no more lines to read, so you can do these to read all input while (gets(line)) {...}
Neo
Post Reply

Return to “C”