Why is my code giving me segmentation faults?

You should probably have a look at https://en.wikipedia.org/wiki/Segmentation_fault.

Basically it means that your code is trying to use data at an address in an invalid way. A common case in C code is something like this:

char * cptr = NULL ;
cptr = some_function_returning_null();
printf("%s\n"cptr);

The memory at pointer cptr has never been set properly. The attempt to print the string will cause a seg fault.

In your case I think isalpha(text) should be isalpha(text[i]), but I doubt this is causing the problem.

Perhaps if you supplied the full trace, including your input arguments, it would be easier to spot the problem.

Leave a Comment