Reputation: 107
I'm learning the basics of objective-C by Reading 'Objective C For Dummies'. I'm using XCode 4.4, and I'm trying to get some simple code to work. This question has been posed online before. However - the code doesn't seem to compile with the new version of XCode.
At issue seems to be the line NSLog (@"Here is some amazing text! %i",c); This throws an 'Expected Expression' Error. Per the previous form posting, I have disabled automatic reference checking in preferences and this still fails.
#include <stdio.h>
int main(int argc, const char * argv[])
{
//declare variables
int a;
int b;
int c;
//set the variables
a = 2;
b = 3;
//Perform the computations
c = a % b;
//Output the results
NSLog (@"Here is some amazing text! %c",c);
return 0;
}
Upvotes: 0
Views: 108
Reputation: 35803
Add #import <Foundation/Foundation.h>
at the top, and change the NSLog
to this:
NSLog (@"Here is some amazing text! %d",c);
Because %c
doesn't mean "a variable called c
", but rather a char
. %d
means an int
, which is what c
is.
Upvotes: 3
Reputation: 81868
You forgot to include the Foundation header:
#import <Foundation/Foundation.h>
Sidenote: The format specifier should be %d
.
Upvotes: 1