Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Spanky Deluxe

macrumors 603
Original poster
Mar 17, 2005
5,291
1,832
London, UK
In my program I need to read in a text file which is simply a single column of numbers separated simply by a carriage return. In the past I've simply used the FILE command, f_in, fscanf and fclose to do this and I've never had a problem. This was when I was codeing in Windows in Salford C.

Now when I use xCode I get a "... has exited due to signal 10 (SIGBUS)" error code when the following code is added through my program:

Code:
/* Opening the input data file */
FILE *f_in;
f_in = fopen("data.txt", "r");

/* Closing the input data file */   
fclose(f_in);

The error also occurs when using the fscanf function to read in the data. I've tried putting the data.txt file in multiple locations but to no avail. I must be missing something here, does Xcode/OS X/Unix use a different file input process than Windows when compiling a program in C?

This is driving me nuts! Any help would be greatly appreciated!!
 
be sure to check the return value of the fopen system call, it could be returning NULL.

I have no idea what happened but I just went back to the program after leaving it alone for half an hour to find it compiles and now runs fine. :confused: I can only guess that when I moved the data.txt file around before and left it in the final place, OS X hadn't quite... errr... 'realised' the file was there, hence the errors earlier.

It works now so I won't question it too much - curiosity killed the cat after all!!

On a side note, in a sudden revelation I suddenly realised that that phrase blatantly came from Schroedinger's cat thought experiment!
 
In my program I need to read in a text file which is simply a single column of numbers separated simply by a carriage return. In the past I've simply used the FILE command, f_in, fscanf and fclose to do this and I've never had a problem. This was when I was codeing in Windows in Salford C.

Code:
/* Opening the input data file */
FILE *f_in;
f_in = fopen("data.txt", "r");

/* Closing the input data file */   
fclose(f_in);

if (f_in == NULL)
printf ("Bugger, only a complete novice would try to use f_in\n");

Xcode is sometimes not so great at noticing things have changed...

Don't blame XCode on stupid programmer errors.
 
Xcode is sometimes not so great at noticing things have changed...

Indeed. I have been forced to relaunch Xcode because it sometimes forgets to update the autocompletion with the new elements I have added. Very annoying.
 
gnasher729 said:
printf ("Bugger, only a complete novice would try to use f_in\n");

gnasher729 said:
Don't blame XCode on stupid programmer errors.

Thanks for being a kind and friendly contributor to the forum without any form of aggresiveness or rudeness. Telling someone not to use one method without giving them any alternatives is always a highly useful method of adding insight and discussion to a situation.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.