signal 10 (SIGBUS) error in c program when using FILE command

Discussion in 'Mac Programming' started by Spanky Deluxe, Oct 29, 2006.

  1. Spanky Deluxe macrumors 601

    Spanky Deluxe

    Joined:
    Mar 17, 2005
    Location:
    London, UK
    #1
    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!!
     
  2. SamMiller0 macrumors member

    SamMiller0

    Joined:
    Aug 17, 2004
    Location:
    San Jose, CA
    #2
    be sure to check the return value of the fopen system call, it could be returning NULL.
     
  3. Spanky Deluxe thread starter macrumors 601

    Spanky Deluxe

    Joined:
    Mar 17, 2005
    Location:
    London, UK
    #3
    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!
     
  4. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #4
    Xcode is sometimes not so great at noticing things have changed...
     
  5. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #5
     
  6. Soulstorm macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #6
    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.
     
  7. Spanky Deluxe thread starter macrumors 601

    Spanky Deluxe

    Joined:
    Mar 17, 2005
    Location:
    London, UK
    #7
    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.
     

Share This Page