Re: reading a line through scanf





pete wrote:
> 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?
>
> #define LENGTH 20
> #define str(x) # x
> #define xstr(x) str(x)
>
> int rc;
> char array[LENGTH + 1];
>
> rc = scanf("%" xstr(LENGTH) "[^\n]%*[^\n]", array);
^
Just a query, should we not write "[^\n]%*1[^\n]", instead? On my gcc
(4.0.0)
it keeps waiting if I don't specify the length.
> if (!feof(stdin)) {
> getchar();
> }
> if (rc == 0) {
> *array = '\0';
> }
>
> /* rc will be either 1, 0, or EOF */
Neat, really very neat!

.



Relevant Pages

  • 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)
  • Re: reading a line through scanf
    ... gyan wrote: ... > I want to read a line with white spaces though scanf. ... Should you not use '\n' instead?And should you not exclude the newline ...
    (comp.lang.c)
  • Re: reading a line through scanf
    ... > pete wrote: ... >>> I want to read a line with white spaces though scanf. ... int main ...
    (comp.lang.c)
  • 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)