scanf can not get the values from keyboard.

This is a discussion on scanf can not get the values from keyboard. within the General Discussions forums, part of the Community Boards category; ooo Hi I am new to C, I have coped the following code from a book. I used visaul C++ ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    1

    Unhappy scanf can not get the values from keyboard.

    ooo

    Hi

    I am new to C, I have coped the following code from a book.

    I used visaul C++ 2008 from Microsoft. the program is a console application.

    I entered a integer from keyboard, but I can see any output on the console.

    (the getchar () is just for the stop the screen, then I can see the results).

    where is wroung?

    Thanks for any helps!!


    Jack



    Code:
    #include <stdio.h>
    
    int main()
    {
      
    int k=1;
       
     printf ("enter an integer  \n" );
     scanf("%d ", &k);
    
    printf (" the entered integer is  :  %d \n  ",  k);
    
    getchar ();
    
    return 0;
    
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,687
    You should remove the trailing spaces on your scanf (and printf) lines.
    "%d", not "%d "
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scanf is changing my results!
    By rogster001 in forum C Programming
    Replies: 8
    Last Post: 08-18-2009, 12:26 PM
  2. disposing error
    By dropper166 in forum C# Programming
    Replies: 2
    Last Post: 03-30-2009, 11:53 PM
  3. Computing Large Values
    By swbluto in forum C++ Programming
    Replies: 8
    Last Post: 04-07-2005, 03:04 AM
  4. Replies: 1
    Last Post: 02-03-2005, 02:33 AM
  5. keeping values of scanf
    By n00by in forum C Programming
    Replies: 1
    Last Post: 04-17-2004, 03:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21