Input control moves to next line automatically without using cout function

Discussion in 'C Programming' started by srini4vasan@gmail.com, Sep 10, 2007.

  1. Guest

    #include <stdio.h>
    int main()
    {

    char n, m;
    puts (" Enter the first string and . to terminate :");
    do
    {
    n = getchar();
    putchar(n);
    }while(n !='.');

    puts (" Enter the second string and . to terminate :");
    do
    {
    m = getchar();
    putchar(m);
    }while( m != '.');

    return 0;
    }

    Output
    ------------
    Enter the first string and . to terminate :
    234.
    234. Enter the second string and . to terminate :

    2343.
    2343.Press any key to continue

    In the above program- output the i can't enter the value of the second
    string in the same line.
    Here control automatically moves to next line.

    ie., The value cannot be entered in the same line even there is no
    corresponding cout function.

    thanks,
    , Sep 10, 2007
    #1
    1. Advertising

  2. Chris Dollin Guest

    wrote:

    > #include <stdio.h>
    > int main()
    > {
    >
    > char n, m;
    > puts (" Enter the first string and . to terminate :");
    > do
    > {
    > n = getchar();
    > putchar(n);
    > }while(n !='.');
    >
    > puts (" Enter the second string and . to terminate :");
    > do
    > {
    > m = getchar();
    > putchar(m);
    > }while( m != '.');
    >
    > return 0;
    > }
    >
    > Output
    > ------------
    > Enter the first string and . to terminate :
    > 234.
    > 234. Enter the second string and . to terminate :
    >
    > 2343.
    > 2343.Press any key to continue
    >
    > In the above program- output the i can't enter the value of the second
    > string in the same line.


    Yes, you can. You just didn't.

    > Here control automatically moves to next line.
    >
    > ie., The value cannot be entered in the same line even there is no
    > corresponding cout function.


    Yes, you can.

    What you /can't/ do is get the prompt out in the middle.

    To do what I think you want to do, you will have to step outside the
    realm of standard C and use some implementation-defined extension.
    IIRC, this is mentioned in the FQX (fx:hint). Once such extension
    is [N]CURSES. You might find it easier to just drop the requirement.

    --
    Chris "oops! concrete floor." Dollin

    Hewlett-Packard Limited registered office: Cain Road, Bracknell,
    registered no: 690597 England Berks RG12 1HN
    Chris Dollin, Sep 10, 2007
    #2
    1. Advertising

  3. Army1987 Guest

    On Mon, 10 Sep 2007 06:35:45 -0700, srini4vasan wrote:

    [snip]
    > In the above program- output the i can't enter the value of the

    second
    > string in the same line.
    > Here control automatically moves to next line.


    Whatever you type will be sent to stdin only when you hit Enter,
    so to allow you to edit lines with backspace without the program
    knowing. See www.c-faq.com, question 19.1.
    --
    Army1987 (Replace "NOSPAM" with "email")
    If you're sending e-mail from a Windows machine, turn off Microsoft's
    stupid “Smart Quotes†feature. This is so you'll avoid sprinkling garbage
    characters through your mail. -- Eric S. Raymond and Rick Moen
    Army1987, Sep 11, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. abi

    man cout or info cout

    abi, Jun 27, 2003, in forum: C++
    Replies:
    2
    Views:
    1,633
  2. Pmb

    std::cout vs cout

    Pmb, Jun 2, 2004, in forum: C++
    Replies:
    2
    Views:
    4,389
    Leor Zolman
    Jun 2, 2004
  3. Deniz Bahar
    Replies:
    2
    Views:
    449
    Andrey Tarasevich
    Mar 9, 2005
  4. Replies:
    4
    Views:
    308
    Howard
    Sep 15, 2005
  5. Stefan Ram

    Re: cout vs std::cout

    Stefan Ram, Sep 28, 2008, in forum: C++
    Replies:
    7
    Views:
    459
Loading...

Share This Page