Re: reading a line through scanf



On Thu, 30 Jun 2005 01:30:36 -0400, gyan wrote:

> I want to read a line with white spaces though scanf.
> So i used:
> scanf("%['/n']",string);
>
> above is working in one program, but in other..what may be the reason?


This scand for a matching sequence of ' / and n characters so I would be
very surprised if this "works" for what you want opn any system.

The appropriate function for reading a line is fgets(). While scanf() can
be made to do this it is not what it is designed for and is awkward. Once
you've read a line you can use all of C's string handing functions
including sscanf() to decode it.

Lawrence

.



Relevant Pages

  • Re: scanf to include white spaces
    ... > I was wondering if there was a way to include the white spaces in a string. ... variable must be an array pointer. ... scanf() stops at white space. ...
    (comp.lang.c)
  • Re: reading a line through scanf
    ... pete wrote: ... > gyan wrote: ... >> I want to read a line with white spaces though scanf. ...
    (comp.lang.c)
  • Re: reading a line through scanf
    ... gyan wrote: ... > I want to read a line with white spaces though scanf. ... Prev by Date: ...
    (comp.lang.c)
  • Re: reading a line through scanf
    ... gyan wrote: ... > I want to read a line with white spaces though scanf. ... Why bother - scanf is not easy to handle. ... Chuck F ...
    (comp.lang.c)