I prefer "%[^\n]s%*c" to eat the newline (* signifies that there is no
variable to capture the character into).

On Sep 4, 11:46 pm, Carlos Guia <[email protected]> wrote:
> I'm not a 100% sure, so who likes this will have to test it before a real
> contest, but I think you can eat the '\n' like this:
> char str[100];
> scanf("%[^\n]s\n",str);
>
> Anyway, I think the cleanest way is to either use getline or fgets.
>
> Carlos Guía
>
> On Sat, Sep 5, 2009 at 12:57 AM, Aditya V Daga <[email protected]> wrote:
>
>
>
> > We can also use
>
> > char str[100];
> > scanf("%[^\n]s",str);getchar();
>
> > (getchar() used for eating '\n' charater)
>
> > On Sat, Sep 5, 2009 at 1:20 AM, vexorian <[email protected]> wrote:
>
> >> string x;
> >> getline(cin, x);
>
> >> Also:
>
> >> char meh[100];
> >> gets(meh);
>
> >> null terminated strings are a bad habit if you plan making apps with C+
> >> + later . I think though that there is a safer version of gets that
> >> takes a limit for the number of characters...
>
> >> On Sep 3, 10:47 pm, 有D <[email protected]> wrote:
> >> > hey, I am not very famliar with C++.
> >> > Can any one tell me how to acquire one line(including space) from the
> >> > console conveniently?
> >> > I used the scanf("%s", &str);
> >> > but it will be cut off if there is any space in your input.
> >> > for example, if you input "hello  world"
> >> > than the world is just omited. str = hello;
>
> >> > --
> >> > 有D >>- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to