Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

willh1234

macrumors newbie
Original poster
Nov 5, 2009
11
0
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.
 
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.
 
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)

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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.