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
int findM(char* arr)
{
int index = -1;
int i = 0;
//Run the code till the end of the string
while(arr[i])
{
//If character M is found assign it to index and break out of the loop
if(arr[i] == \'M\')
{
index = i;
break;
}
i = i+1;
}
return index;
}
