C Function to check occurrence of a character in a particular string
/*
* Returns index of the first occurrence of the character
* else returns -1 if the character is not present
*/
int checkChar(char *string, char ch)
{
int index;
if(string == NULL)
return -1;
for (index = 0 ; index < strlen(string); index++)
{
if(string[index] == ch)
break;
}
if(index == strlen(string)
return -1;
return index;
}
Comments
Post a Comment