![]() |
Segmentation fault in porgram
Below is the program for sorting the file in ascending and reverse order
this program is working properly under window but it gives segmentation fault under unix Can u find where i m mistaking.... :( u can give command line arguments like this ./myprogram -a filename.txt for sortin filename in ascending order ./myprogram -r filename.txt for sorting filename in reverse order Program Code:
#include <stdio.h> |
Re: Segmentation fault in porgram
This is the Introduce yourself section....
|
Re: Segmentation fault in porgram
Moved to C-C++ forum.
|
Re: Segmentation fault in porgram
1. main returns int, not void
2. (*fgets(buffer,(BUFFER_LEN-1),fp) != '\0') When fgets() reaches the end, it returns NULL. Then when you try to dereference that result, you segfault. The correct loop condition is fgets(buffer,(BUFFER_LEN-1),fp) != NULL Also, you don't have to account for the \0 in your count, so you can just do fgets(buffer,BUFFER_LEN,fp) != NULL |
| All times are GMT +5.5. The time now is 12:34. |