Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A couple questions from my feeble mind about Objective-C

  1. May 22, 2012 #1
    Okay. A few questions.

    Is there an escape character similar to '%s' which uses an NSString instead of a C-style string, so I could do something like NSLog(@"Hello, %N!",/*Insert NSString* here*/)?

    I tried the following code:

    Code (Text):
    #import <Foundation/Foundation.h>

    @interface Greeter : NSObject
    {
        char name[256];
    }
    -(void)setname : (char[256])newname;
    -(void)greet;
    -(char[256])getname;
    @end

    @implementation Greeter
    -(void)setname : (char[256])newname
    {
        for (int i = 0;i<256;i++)
        {
            name[i]=newname[i];
        }
    }
    -(void)greet
    {
        printf("Hello, %s!",name);
    }
    -(char[256])getname
    {
        return name;
    }
    @end
    It's not happy with my return name; expression. My mistake's probably really obvious, but what is it? Maybe I should have it return char* instead?
     
    Last edited: May 22, 2012
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: A couple questions from my feeble mind about Objective-C
  1. Question about C (Replies: 3)

  2. Questions about C (Replies: 7)

Loading...