Re: reading a line through scanf
- From: "Suman" <skarpio@xxxxxxxxx>
- Date: 29 Jun 2005 23:40:32 -0700
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!
.
- Follow-Ups:
- Re: reading a line through scanf
- From: pete
- Re: reading a line through scanf
- From: pete
- Re: reading a line through scanf
- References:
- reading a line through scanf
- From: gyan
- Re: reading a line through scanf
- From: pete
- reading a line through scanf
- Prev by Date: Re: reading a line through scanf
- Next by Date: Re: C directives
- Previous by thread: Re: reading a line through scanf
- Next by thread: Re: reading a line through scanf
- Index(es):
Relevant Pages
|