49 lines
684 B
C++
49 lines
684 B
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
|
|
camelCase
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <cctype>
|
|
|
|
#define SIZE 100+1
|
|
|
|
using namespace std;
|
|
|
|
char *camelCase(char *const str);
|
|
|
|
int main(void) {
|
|
char str[SIZE];
|
|
|
|
cout << "Inserisci una frase: ";
|
|
cin.getline(str, SIZE);
|
|
|
|
camelCase(str);
|
|
|
|
cout << "Frase aggiornata: " << str << endl;
|
|
|
|
return 0;
|
|
}
|
|
|
|
char *camelCase(char *const str) {
|
|
if (str[0] == '\0') {
|
|
return str;
|
|
}
|
|
|
|
str[0] = toupper(str[0]);
|
|
|
|
|
|
int i = 1;
|
|
while (str[i] != '\0') {
|
|
if (isalpha(str[i]) && isblank(str[i - 1])) {
|
|
str[i] = toupper(str[i]);
|
|
} else {
|
|
str[i] = tolower(str[i]);
|
|
}
|
|
i++;
|
|
}
|
|
|
|
return str;
|
|
} |