Results 1 to 3 of 3

Thread: Input from Keyboard

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Input from Keyboard

    When I use this code:

    Code:
        printf("Do you want to enter another student? [y/n]");
      scanf("%c",&v);
      if(v=='y'){
        goto EnterStudent;
       }
    It doesn't allow me to input data from the keyboard but instead it move right to the prompt... All of the files I have opened are closed, so I don't know where it is pulling the data from....

    Is there any way to ensure that the data is inputted from the keyboard?

    thnx,
    squirrelly1
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Look into gets() and getc() for direct keyborad input - gets() waits for a return key press before returning data to the program, getc() returns each keystroke.

    C++ has iostream which gives you .getline

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It probably reads an old newline still in the pipeline. You could try adding this before reading:
    fseek(stdin, 0, SEEK_END);
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width