lil problem, i'm an idiot

This is a discussion on lil problem, i'm an idiot within the C Programming forums, part of the General Programming Boards category; ok why does my program not even allow me to enter in a character for the "c" variable? heres the ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    40

    lil problem, i'm an idiot

    ok why does my program not even allow me to enter in a character for the "c" variable?

    heres the code:

    Code:
    #include <stdio.h>
    
    main()
    {
         int board[30][30] = {{0}, {0}};
         int b_rows, b_cols;
         char gem[27];
         int gem_value[27];
         char c;
    
         scanf("%d%d", &b_rows, &b_cols);
         printf("Rows = %d Cols = %d\n", b_rows, b_cols);
    
         printf("Enter a Character: ");
         scanf("%c", &c);
         printf("%c", c);
         return 0;
    }
    here's the output:

    Code:
    4 5
    Rows = 4 Cols = 5
    Enter a Character:
    %
    its not even allowing me to enter a character in, what simple thing am i missing?

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Look up flushing the input buffer.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Must be reading the newline from your first scanf.

    see if doing the following works.

    printf("Enter a Character: ");
    scanf("%*c%c", &c);
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  5. Segmentation Fault Problem: Urgent Help
    By bodydrop in forum C Programming
    Replies: 3
    Last Post: 05-05-2006, 09:02 PM

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