Given a string, write a recursive function to find its first uppercase letter. Your function should
return the letter.
Function Prototype: char findUppercase(char* str);
#include <iostream>
using namespace std;
char findUppercase(char* str) {
if (str[0] == '\0') {
return '\0';
}
if (str[0] >= 'A' && str[0] <= 'Z') {
return str[0];
}
return findUppercase(str+1);
}
int main() {
char str[] = "this is a Test string";
cout << "The first uppecase letter is \'"
<< findUppercase(str) << "\'";
return 0;
}
Comments
Leave a comment