I have looked at test case 3. My test program looks like this:
char testcase3[] = " But... This iS not THAT COMPLEX";
char* data = testcase3;
char* result = rcapitalize(data);
printf("%s\n", result);
As the isalpha() function evaluates one (or more) points as false, the T of But is capitalized. If this result is not desired, the question would be which rule should apply. If the last letter at the end of a sentence should always be capitalized, but not if two or more dots follow, a rule would be required, which is missing here.
//edit:
Obviously you have to take care of full stops and commas.
char* rcapitalize(char* str)
{
int i = 0;
while (str[i] != '\0') {
if ((str[i] == '.' || str[i] == ',') && i > 0) {
}
else {
if (!isalpha(str[i + 1]) || str[i + 1] == '\0') {
str[i] = toupper(str[i]);
}
else {
str[i] = tolower(str[i]);
}
}
i++;
}
return str;
}
Instead of the while loop, I would recommend a for loop.
for (int i = 0; str[i] != '\0'; i++) { ...