【发布时间】:2012-07-02 23:21:05
【问题描述】:
我不确定我在这里做错了什么。我还尝试使用以下方法在foo 中设置s1..3:
s1 = [[NSString alloc] initWithString:[filepaths objectAtIndex:0]];
上下文如下:
void foo(NSString *s1, NSString *s2, NSString *s3){
//assign long string to NSString *fps
//...
//break fps into smaller bits
NSArray *filepaths = [fps componentsSeparatedByString:@"\n"];
//the above worked! now let's assign them to the pointers
s1 = [filepaths objectAtIndex:0];
//repeat for s2 and s3
NSLog(@"%@",s1); //it worked! we're done in this function
}
int main(int argc, const char * argv[]){
NSString *s1 = nil; //s2 and s3 as well
foo(s1,s2,s3); //this should work
NSLog(@"%@",s1); //UH OH, this is null!
return 0;
}
【问题讨论】:
标签: cocoa pointers parameter-passing