I am having problem with a C program.
I know that strchr()
is causing the problem, and it is returning
Segmentation Fault
My code is as follows:
char *pointer;
pointer = strchr(string, character);
I don't know why I'm getting the error message. One thing I can guess is that my 'string' sometimes doesn't contain the character. Could that be the reason why?
How can I stop it, as I don't have control over the input string?
Full code
int index(const char *string, char character)
{
const char *pointer;
pointer = strchr(string, character);
if(pointer)
return (pointer - string);
else
return -1;
}