The “Stopping” statement never gets printed even if you type ‘stop’ when running the program. Is the initWithUTF8String: method introducing extra formatting?
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
char holderText[256];
fgets(holderText, 256, stdin);
NSString *words = [[NSString alloc] initWithUTF8String:holderText];
if ([words isEqualToString:@"stop"]) {
NSLog(@"STOPPING");
}
NSLog(@"This is what you typed: %@", words);
[pool drain];
return 0;
}
The code looks fine, even though you’re leaking the
wordsstring. You need to add an[autorelease]on the end of that alloc call.You could try
initWithCStringand also trim new lines and surrounding whitespace.