Re: reading a line through scanf



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);
if (!feof(stdin)) {
getchar();
}
if (rc == 0) {
*array = '\0';
}

/* rc will be either 1, 0, or EOF */

--
pete
.



Relevant Pages

  • 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. ... 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)
  • reading a line through scanf
    ... I want to read a line with white spaces though scanf. ... above is working in one program, but in other..what may be the reason? ... Prev by Date: ...
    (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)