Thread: Why isnt my loop working?

  1. #1
    Registered User Sietor's Avatar
    Join Date
    Aug 2016
    Location
    Sweden
    Posts
    13

    Why isnt my loop working?

    So this is my loop:
    Code:
    int main()
    {
        char Button;
    
    
    
    
        do{
    
    
        printf("Press E \n");
        scanf(" %c", Button);
    
    
        }while(Button != 'E');
    
    
        printf("Good");
    
    
        return 0;
    }
    The point is that is should loop back if the User pressed a worng button.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    You need to pass the address of Button, rather than the value of Button to scanf.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User Sietor's Avatar
    Join Date
    Aug 2016
    Location
    Sweden
    Posts
    13
    How do i pass the address of Button?

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    The '&' symbol is used as the address-of operator in C. Place it in front of Button, in the call to scanf, but nowhere else in your program.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  5. #5
    Registered User Sietor's Avatar
    Join Date
    Aug 2016
    Location
    Sweden
    Posts
    13
    Thanks!

  6. #6
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Please format your code before presenting here. Try to avoid extra blank lines also.

    Please not the changes I made to your code.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       char Button;
    
       do{
          printf("Press E \n");
          scanf(" %c", &Button);
       }while(Button != 'E');
    
       printf("Good\n");
    
       return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Im confused why this isnt working
    By lavaboy in forum C Programming
    Replies: 9
    Last Post: 04-15-2014, 07:56 AM
  2. not sure why my loop isnt working....
    By cprogrammer1980 in forum C Programming
    Replies: 3
    Last Post: 03-11-2011, 12:41 PM
  3. Ummm, why isnt this working?
    By gp364481 in forum C Programming
    Replies: 5
    Last Post: 04-13-2010, 08:39 AM
  4. EOF isnt working....
    By i_can_do_this in forum C Programming
    Replies: 2
    Last Post: 07-10-2006, 09:58 AM
  5. why isnt my switch working
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-21-2002, 12:08 PM

Tags for this Thread