[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: A simple C doubt



On Wednesday 20 August 2003 07:27, Jan Ekholm wrote:
> On Wed, 20 Aug 2003, [iso-8859-1] Igor Cabral Corrêa wrote:
> >How can I read these 4 lines? Using something like
> >
> >for (int i=0; i<4; i++) scanf("%s", line);
> >
> >the empty line will be skipped, and I don?t know that. Someone knows
> > an easy way to do it? PS.:  I know how many lines I want to read.
>
> I'd say fgets() is what you want to use to read lines. Later you can
> use sscanf()  on those lines if you want to. The actual implementation
> is however left as an excercise to the reader.

As a little additional note: scanf() is also dangerous (although that 
might not play a real role in your case), as it is very prone to causing 
buffer overflows...

-- 
Christian Reiniger

Very funny, Scotty! Now beam up my clothes...