Segmentation errors on the server, but not local machines

As stated in the title, the program is running on my local machine (ubuntu 9.10) but not on the server (linux). It is a grid hosting package from godaddy.

Please help..

This is the code:

#include 
#include

int main(int argc, char **argv)
{
long offset;
FILE *io;
unsigned char found;
unsigned long loc;

if (argc != 2)
{
printf("syntax: find 0000000 ");
return 255;
}

offset = atol(argv[1]) * (sizeof(unsigned char)+sizeof(unsigned long));

io = fopen("index.dat","rb");
fseek(io,offset,SEEK_SET);
fread(&found,sizeof(unsigned char),1,io);
fread(&loc,sizeof(unsigned long),1,io);

if (found == 1)
printf("%d ",loc);
else
printf("-1 ");

fclose(io);

return 0;
}

< p>Edit: This is not my plan.
I hope I know enough C to solve it, but I have reached the deadline. The program aims to find the first 7-digit number in the PI sequence, index. dat contains a huge array => location.

http://jclement.ca/fun/pi/search.cgi

Edit 2: I have used the updated code and the null pointer test, and still get the same results.< br>The program runs normally on my local computer, and this error only occurs on the server.

The most likely thing is that fopen failed-you didn’t check its return value to see if you really have a valid pointer. (When you try to use the NULL pointer in the next line, a segfault will occur.)

As stated in the title, the program is running on my local machine (ubuntu 9.10), but not on the server (linux). It is a grid hosting package from godaddy.

Please help..

This is the code:

#include 
#include

int main(int argc, char **argv)
{
long offset;
FILE *io;
unsigned char found;
unsigned long loc;

if (argc != 2)
{
printf("syntax: find 0000000 ");
return 255;
}

offset = atol(argv[1]) * (sizeof(unsigned char)+sizeof(unsigned long));

io = fopen("index.dat","rb");
fseek(io,offset,SEEK_SET);
fread(&found,sizeof(unsigned char),1,io);
fread (&loc,sizeof(unsigned long),1,io);

if (fou nd == 1)
printf("%d ",loc);
else
printf("-1 ");

fclose( io);

return 0;
}

Edit: This is not my plan.
I hope I know enough C to solve it, but I The deadline has been reached. The program aims to find the first 7-digit number in the PI sequence, index.dat contains a huge array => location.

http://jclement.ca/fun /pi/search.cgi

Edit 2: I have used the updated code and the null pointer test, and still get the same results.
The program runs normally on my local computer, this error is only Happened on the server.

The most likely thing is that fopen failed-you did not check its return value to see if you really have a valid pointer . (When you try to use the NULL pointer in the next line, a segfault will occur.)

Leave a Comment

Your email address will not be published.