Error using 'A' to 'Z'

Discussion in 'iOS Programming' started by willh1234, Apr 18, 2010.

  1. willh1234 macrumors newbie

    Joined:
    Nov 5, 2009
    #1
    I am getting errors when using the following code:

    Code:
    char c;
    for(c = 'A';c<='Z';c++)
    
    I am getting errors such as
    Code:
    src/MusicViewController.m:30: error: stray ‘\342’ in program
    src/MusicViewController.m:30: error: stray ‘\200’ in program
    src/MusicViewController.m:30: error: stray ‘\230’ in program
    src/MusicViewController.m:30: error: stray ‘\342’ in program
    src/MusicViewController.m:30: error: stray ‘\200’ in program
    src/MusicViewController.m:30: error: stray ‘\231’ in program
    src/MusicViewController.m:30: error: ‘Z’ undeclared (first use in this function)
    
    AFAIK this code is perfectly fine but wont seem to compile.
     
  2. PatrickCocoa macrumors 6502a

    Joined:
    Dec 2, 2008
    #2
    I don't know. A few comments:
    1. You might want to switch to NSString and its methods rather than char. I'm not sure if you're a beginner to Cocoa, but if you are, switch to NSString.

    2. You may want to change your loop to 'A' to 'B' and see if you still get the error messages.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    This code compiles and runs fine for me. Probably something elsewhere in your code. What happens inside the for loop?
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    The "stray" values listed are UTF8 sequences for curly quotes. The triplet \342\200\230 is the opening one, and the \342\200\231 is the closing one.

    Whatever you used to edit your program, it converted your quotes from plain Apostrophes to curly quotes. You need to use this character:
    Code:
    [SIZE="5"] '[/SIZE]
    
    not these
    Code:
    [SIZE="5"] ‘ ’ [/SIZE]
    They may look similar, or even the same, depending on what font you're seeing them in, but they are completely different. I have enlarged the font so any differences are more apparent.

    It might help if you tell us what editor you're using, whether you copied and pasted the text from somewhere like a web page (which often contain curly quotes), and other details. Some editors, especially those for writing documents, will automatically substitute curly quotes. You don't want any of those things to happen. You just want plain ordinary apostrophe.

    Or just copy and paste the above single apostrophe into your text file.
     
  5. willh1234 thread starter macrumors newbie

    Joined:
    Nov 5, 2009
    #5
    That solved it thanks :) I'm using gedit on Ubuntu to do my dev and the font is really small so I didn't notice my mistake.
     

Share This Page