0

I got a gcc "Segmentation Fault" error with this script : http://paste2.org/p/1397204, why ?

I tested this code with Visual C++ compiler and I don't get any error...

bernedef
  • 699
  • 2
  • 12
  • 22
  • possible duplicate of [Getting Segmentation Fault](http://stackoverflow.com/questions/5834032/getting-segmentation-fault) – MByD May 03 '11 at 17:24
  • Can you help me to fix my code ? – bernedef May 03 '11 at 17:24
  • Sure. instead of `printf("|%s|\n", trim(" MyStringHaveToBeTrimmed "));`, do `char str[] = " MyStringHaveToBeTrimmed ";printf("|%s|\n", trim(str));` – MByD May 03 '11 at 17:27
  • And if you looked over my answer to case 1, you would have seen this fix... – MByD May 03 '11 at 17:28

1 Answers1

0

Thanks to MByD according to Getting Segmentation Fault topic.

Replace :

printf("|%s|\n", trim("  MyStringHaveToBeTrimmed  "));

With :

char str[] = "  MyStringHaveToBeTrimmed  ";
printf("|%s|\n", trim(str));

New code : http://paste2.org/p/1397248

Community
  • 1
  • 1
bernedef
  • 699
  • 2
  • 12
  • 22
  • please mark it as accepted answer when you can, so people will know it's solved. In the meantime, add [solved] to the title of the question. – MByD May 03 '11 at 18:01
  • I got this box : "You can accept your own answer in 2 days", so I'll change question status as answered in 2 days... – bernedef May 03 '11 at 18:02