I have some c code that works fine on a unix server (which I have come to understand is based on "System V" unix), but it blows up on my local macbook (which I have come to understand is "classic" unix).
The purpose of the code is to take a ascii file and form it into a series of structures, then rewrite it to a separate file in binary.
When I run the program, I get a Bus error.
int main( void )
FILE *from, *to;
printf("\nEnter the name of your file: ");
from = fopen(filename, "r");
printf("Error opening file\n");
sprintf(filename, "%s.bn", filename);
to = fopen(filename, "wb");
printf("Error opening to file\n");
while(fgets(buff, sizeof(buff), from) != NULL)
if (sscanf(buff, "*format of Class struct*****, etc, etc, etc)) == 21)
fwrite (&buf, 1, sizeof(buf), to);
When I run the debugger, it says the problem is in the fgets function.
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000038
0x9008b0e9 in fgets ()