Sunday, August 2, 2009

Segmentation fault in C program?

this program is for sorting the file and displaying it on monitor...........


this is working nice in window but give segmentation fault in unix





i m storing address of strings in array of pointers..and then sorting it with bubble sort





here is the small part of program





buffer is for storing strings


pS is array of string pointers





if u want whole program for debuggin mail me ank_rishi23@yahoo.com





while((*fgets(buffer,(BUFFER_LEN-1),fp... != '\0') %26amp;%26amp; (i %26lt; NUM_P))


{


pS[i] = (char*)malloc(strlen(buffer) + 1);


if(pS[i]==NULL) /* Check for no memory allocated */


{


printf(" Memory allocation failed. Program terminated.\n");


return;


}


strcpy(pS[i++], buffer);


}


last_string = i;





where can be segmentation fault...........?? plz find.....

Segmentation fault in C program?
since its working on windows, the segmentation fault could be that unix does not recognize something in it.





from what i know, windows and unix have different ways of representing data. some have larger sizes.





so the error could be in the size. check the malloc to see if its causing the segmentation fault
Reply:May is virus ``KIlls virus `` `


You have two memory? Have a memory problem of the ``


I think you ,so going to http://www.ePathChina.com

crab apple

No comments:

Post a Comment