我是一个新手,所以请不要对我大喊大叫。
我想写的是这样的:
#include <stdio.h>
int main() {
int age = 17;
//I'm trying to assign a string value to a class call name.
//Now I know there are different types of specifiers: %i for int, %@ for NSString etc.
//but what I want to do is this
int name = "PJ" //Which is completely wrong I know but the only other way that I found
//is to use NSString but that means I would need to use the NSObject
//Library which I don't want to get into yet, I want to keep it simple
printf("Hello World, my name is %@ and I'm %d years old\n", name, age);
}
我相信您正在寻找的是:
const char *name = "PJ"
另外,您可能希望将打印语句更改为:
printf("Hello World, my name is %s and I'm %d years old\n", name, age);
否则,如下面@HotLicks所评论,它将崩溃。
正如您可能已经推断出的那样,C比Objective-C多得多:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句