Welcome, Guest. Please login or register.
Did you miss your activation email?
April 26, 2017, 12:40:46 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Chapter Study
| | |-+ Chapter 13 - Underlying C Language Features
| | | |-+ What's wrong with this code snippet?
Pages: [1] Go Down
Author Topic: What's wrong with this code snippet? (Read 2035 times)
Posts: 14

on: September 09, 2009, 09:18:43 AM

I think this should work, but it doesn't.  I must be missing something very basic.

const NSString words[] = {@"Happy", @"Birthday"};
NSString *word;
word = @"Birthday";
word = words[1];   

At the last line, the compiler says "error: incompatible types in assignment."  But words[1] is @"Birthday".  So why is it OK to set word equal to @"Birthday" but not OK to set it equal to words[1]?
Global Moderator
Full Member
Posts: 212

Reply #1 on: September 09, 2009, 10:37:06 AM

Just as word is a pointer to an NSString object, words needs to be an array of pointers to NSString objects.
You forgot the *

const NSString *words[] = {@"Happy", @"Birthday"};

Sanity: Minds are like parachutes. Just because you've lost yours doesn't mean you can borrow mine.

Pages: [1] Go Up
Jump to:

Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.