Give the c code for a function called findM that takes a cha
Give the c code for a function called findM that takes a character array (string) as a parameter and returns an integer that is the array index of the first occurence of an uppercase \'M\'. If no \'M\' is found the function should return -1. Only submit the code for the function, no other c code is necessary.
Solution
note*: you need to use #include <string.h>
you need to call from main as
char str[100]=\"This is SampMle String\";
int index = findM(str);
Here is code:
int findM(char str[100])
{
char * pch;
pch=strchr(str,\'M\'); // retrun first occurence of M if nor null
if(pch == NULL)
return -1;
else
return pch-str+1;
}
