现在,我知道这对于 MacOS 来说是一个简单的问题,但是当我编译一个包含 'arc4random % n' 的代码时,我只是在终端中收到一条错误日志:
main.m:9: error: ‘arc4random’ undeclared (first use in this function)
main.m:9: error: (Each undeclared identifier is reported only once
main.m:9: error: for each function it appears in.)
我使用:
gcc `gnustep-config --objc-flags` -lgnustep-base main.m -o main
编译它
这是我的代码(如果有帮助的话):
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int number, guess;
number = arc4random() % 101;
while (!guess == number) {
NSLog (@"Please guess a number between 1 and 100");
scanf ("%i", &guess);
if (guess < number) {
NSLog (@"Sorry, guessed too low!");
}
else if (guess > number) {
NSLog (@"Sorry, guessed too high!");
}
}
NSLog (@"You guessed correct!");
[pool drain];
return 0;
}