Parse error beofore ")" token

Discussion in 'Mac Programming' started by Quboid, Oct 26, 2006.

  1. Quboid macrumors 6502

    Joined:
    Oct 16, 2006
    Location:
    everywhere
    #1
    Hey,
    I'm new to programming in C, and i have been having a problem with a simple program that i recently coded. Xcode is giving me parse error message for an "if" line that i can almost swear is right. Check it out.

    #include<stdio.h>
    #include<math.h>
    int a, b, d, e, f ;
    char c;

    int main (void)
    {
    printf("enter a number");
    scanf("%i",&a);
    printf("enter another number");
    scanf("%i",&b);
    Printf("this is the menu");
    Printf("\n 1. *");
    printf("\n 2. +");
    printf("\n 3. -");
    printf("\n 4. /");
    printf("\n 5. %");
    printf("\n 6. ^");
    scanf("%char",&c);

    if(c==*){
    d=a*b;
    }
    if(c==+){
    d=a+b;}

    the error message is "parse error before ")" token. I am not sure what the error is , but i've tried eveything i could, can someone help me out? i have an exam soon and i want to be up to mark.
    Thanks..
     
  2. iMeowbot macrumors G3

    iMeowbot

    Joined:
    Aug 30, 2003
    #2
    if(c==*){

    and

    if(c==+){

    are your immediate problems.

    Since you are trying to compare chars, you need to put '*' and '+' inside single quotes.

    The last scanf() is going to need work too, you will want to look a little more closely at the function documentation.
     
  3. dcv macrumors G3

    Joined:
    May 24, 2005
    #3
    It's years since I looked at C but surely you need to enclose the string literal in quotes?

    Code:
    		if(c==[color=red]"[/color]*[color=red]"[/color]){
    		d=a*b;
    		}
    		if(c==[color=red]"[/color]+[color=red]"[/color]){
    		d=a+b;}
    

    (sorry can't quite remember if it's double or single quotes you need though)
     
  4. bbarnhart macrumors 6502a

    bbarnhart

    Joined:
    Jan 16, 2002
    Location:
    Stilwell, Kansas
    #4
    I see three issues:

    1. printf is spelled with a capitol p in some cases.

    2. if (c==*) should be if (c == '*')

    3. The main function is missing a closing curly bracket.
     
  5. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #5
    Quotation marks for strings of characters and apostrophes for single characters.
     
  6. Soulstorm macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #6
    Oh, and... please use code tags. Not using them will result in frustration of every programmer here trying to figure out what you write in the code, since there is no identation outside code tags.
     
  7. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #7
    It's also helpful to point out which line it gave you the error in (copying and pasting the debugger messages can help too). That way we know where in your code to start looking.
     
  8. dernhelm macrumors 68000

    dernhelm

    Joined:
    May 20, 2002
    Location:
    middle earth
    #8
    And it is never too early to learn that are ignoring return values of functions at your own risk...
     
  9. jlcharles macrumors 6502

    Joined:
    Mar 30, 2006
    Location:
    Wenonah, NJ
    #9
    If you give a menu with numbers, why are you checking for the symbol? Wouldn't it make more sense to make c an int?

    And then, by using a menu like that, I prefer to use a case statement.
     
  10. ATG macrumors regular

    Joined:
    Aug 7, 2005
    #10
    It's normally best for new programmers to develop their own style - not some else's. Unless it's generally accepted to do it the other way for a very good reason.
     

Share This Page