How do you enter a string like "hello world" from the keyboard?

I need to enter sentences and save them in the 'msg' array.
I have tried a number of ways, but alas, to no avail.

For instance:

for(i=0; (c=getchar())!='
'; ++i)
{
msg[i]=c;
}
msg[i]='';

When I run the program it completely bypasses the loop. Ive tried flushing the input too. No luck.

Any ideas?

Comments

  • Just fixed it!
    Put the line below in front. Works fine!

    c=getchar();

    for(i=0; (c=getchar())!='
    '; ++i)
    {
    msg[i]=c;
    }
    msg[i]='';

    Jon.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion