Please Help me with simple code!

This is a discussion on Please Help me with simple code! within the C Programming forums, part of the General Programming Boards category; Yay! First Post! Heres the code: Code: #include <stdio.h> main(){ char pay='s'; do { scanf ("%c",pay); if (pay=='s'; printf("Salary Paid"); ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    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, 07: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, 11:51 AM
  4. Simple Code, looking for input.
    By Alien_Freak in forum C Programming
    Replies: 3
    Last Post: 03-03-2002, 10:34 AM

Tags for this Thread


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