Thread: Please Help me with simple code!

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

    Please Help me with simple code!

    Yay! First Post! Heres the code:

    Code:
    #include <stdio.h>
    main(){
    char pay='s';
    
    
    do {
    scanf ("%c",pay);
    if (pay=='s'; printf("Salary Paid");
    else if pay=='h'; printf("Hourly Pay");
    } while (pay=='s');
    return 0; }
    I don't know why it keeps saying segmentation fault. What seems to be the problem?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > if (pay=='s'; printf("Salary Paid");
    How are you getting a segfault, when this won't even compile?

    > scanf ("%c",pay);
    Well you forgot the & here.
    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.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    scanf() needs the address of the variable to store the input in:
    Code:
    scanf ("%c",&pay);
    EDIT: Beaten to the punch by Salem.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 11-23-2005, 08:53 AM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Windows Programming
    Replies: 0
    Last Post: 10-14-2002, 01:29 PM
  3. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM
  4. Simple Code, looking for input.
    By Alien_Freak in forum C Programming
    Replies: 3
    Last Post: 03-03-2002, 11:34 AM

Tags for this Thread