joaopenteado
joaopenteado

Reputation: 118

Program received signal from GDB: EXC_BAD_ACCESS

Well, I'm starting development on the Mac OS X this code that you'll see is in a book that I bought, really basic like Chapter 3. And I can't run it. PLEASE HELP ME:

C301.m :

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
 if (argc == 1) {
  NSLog (@"You need to provide a file name");
  return -1;
 }
 FILE  *wordFile = fopen("tmp/words.txt", "r");
 char word[100];
 while (fgets(word, 100, wordFile)) {
  word[strlen(word) - 1] = '\0';
  NSLog(@"%s is %d characters long", word, strlen(word));
 }
 fclose(wordFile);
    return 0;
} //main

The file is in its place.

Thank you so much!

Upvotes: 0

Views: 613

Answers (1)

Employed Russian
Employed Russian

Reputation: 213526

I am guessing wordFile is NULL (you should check for this); that you are mistaken: the file in fact does not exist, and finally that you really meant "/tmp/words.txt" instead of "tmp/words.txt"

Upvotes: 1

Related Questions