I hope I formatted the code correctly this time. Let me say first that the code works as is; it's in understanding some parts and modifying others that I run into trouble.
I'm going to delete my numerous comments and limit myself to a few questions on it. 1. Is FILE a keyword in Obj-C? What is its function? Why all caps? 2. What does "r" do? 3. The text file already has strings containing empty spaces, each ending with \n; why not make them NSStrings instead of c-strings? 4. Why, when I try to change the launch parameter of the file (using executables, clicking on arguments and plus, and typing in the parameter) to anything other than /tmp (such as /Desktop), do I get errors? After all, /tmp is a volatile, vulnerable place. This is the error I got for /Desktop: The Debugger has exited due to signal 10 (SIGBUS).
Here's the code:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
if (argc == 1)
{
NSLog(@"You need to provide a file name");
return 1;
}
FILE *wordFile = fopen(argv[1], "r");
char word[100];
while (fgets (word, 100, wordFile))
{
word[strlen(word) - 1] = '\0';
NSLog(@"%s is %d characs long", word, strlen(word));
}
fclose (wordFile);
[pool drain];
return 0;
}