c++ Mac OS X stray \20 error

Discussion in 'Mac Programming' started by paulmcco, Aug 25, 2011.

  1. paulmcco macrumors newbie

    Joined:
    Jul 26, 2011
    #1
    Hello, I get this error from code within a header file...any ideas?

    ScorePlayerMatch.h:25: error: stray '\20' in program
    ScorePlayerMatch.h:25: error: parse error before numeric constant


    Code:
    #include <Carbon/Carbon.h>
    struct scoreMatch {
    	double scoreArr[5][2];
    }ScorePlayerMatch();
    
    scoreMatch ScorePlayerMatch(double pair, double threeKind, double twoPair, double fourKind, double fullHouse, double pairCard, double secPairCard, double threeKindCard, double highC, double lowC)
    {
    	scoreMatch infunc;
    	infunc.scoreArr[0][0] = pair; 
    	infunc.scoreArr[0][1] = 2.0*pow(10.0,6.0) + (pairCard * 10000.0) + (highC) + (lowC/100.0);
    	infunc.scoreArr[1][0] = threeKind; 
    	infunc.scoreArr[1][1] = 4.0*pow(10.0,6.0) + (pairCard * 10000.0) + (highC) + (lowC/100.0);
    	infunc.scoreArr[2][0] = twoPair; 
    	infunc.scoreArr[2][1] = 3.0*pow(10.0,6.0) + (pairCard* 10000.0) + (secPairCard*100.0) + (highC) + (lowC/100.0);
    	infunc.scoreArr[3][0] = fourKind; 
    	infunc.scoreArr[3][1] = (8.0*pow(10.0,6.0)) + (pairCard * (1.0 * pow(10.0,4.0))) + (highC) + (lowC/100.0);
    	infunc.scoreArr[4][0] = fullHouse; 
    	infunc.scoreArr[4][1] = 7.0*pow(10.0,6.0) + (pairCard*10000.0) + (threeKindCard*100.0) + (highC) + (lowC/100.0);
    		
    	return infunc;
    }
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    One idea: don't write functions in header files.

    Another:
    od -ta thefile.h
    Look through the output for the rogue character, then remove it.

    -Lee
     
  3. lloyddean, Aug 25, 2011
    Last edited: Aug 25, 2011

    lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #3
    Code:
    #include <cmath>
    
    struct scoreMatch {
        double scoreArr[5][2];
    };
    
    scoreMatch ScorePlayerMatch();
    
    scoreMatch ScorePlayerMatch(double pair, double threeKind, double twoPair, double fourKind, double fullHouse, double pairCard, double secPairCard, double threeKindCard, double highC, double lowC)
    {
        scoreMatch infunc;
        infunc.scoreArr[0][0] = pair; 
        infunc.scoreArr[0][1] = 2.0*pow(10.0,6.0) + (pairCard * 10000.0) + (highC) + (lowC/100.0);
        infunc.scoreArr[1][0] = threeKind; 
        infunc.scoreArr[1][1] = 4.0*pow(10.0,6.0) + (pairCard * 10000.0) + (highC) + (lowC/100.0);
        infunc.scoreArr[2][0] = twoPair; 
        infunc.scoreArr[2][1] = 3.0*pow(10.0,6.0) + (pairCard* 10000.0) + (secPairCard*100.0) + (highC) + (lowC/100.0);
        infunc.scoreArr[3][0] = fourKind; 
        infunc.scoreArr[3][1] = (8.0*pow(10.0,6.0)) + (pairCard * (1.0 * pow(10.0,4.0))) + (highC) + (lowC/100.0);
        infunc.scoreArr[4][0] = fullHouse; 
        infunc.scoreArr[4][1] = 7.0*pow(10.0,6.0) + (pairCard*10000.0) + (threeKindCard*100.0) + (highC) + (lowC/100.0);
            
        return infunc;
    }
    
     
  4. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #4
    Well, the compiler tells you.
    There's a character in your file that doesn't belong there.
    It's not a printable character, that's why the compiler shows it in octal. ("\20").
    Find out who to see characters in your source file that are normally invisibile.
    Then delete anything that doesn't belong there.
     
  5. Sander macrumors 6502

    Joined:
    Apr 24, 2008
    #5
    The snippet you posted is less than 25 lines, so it's perhaps somewhere else.

    One often-occurring cause for having weird characters in your source files is copying it off a web site. Did you type in this code yourself, directly in Xcode?

    Also, \20 is ASCII 16, which is a rare control character ("Data Link Escape"). Maybe you ended up feeding UTF8 code to the compiler or something?
     

Share This Page