/* Nome: Mario Cognome: Montanari tripleDigit */ #include #include #include #define SIZE 100+1 using namespace std; char *tripleDigit(char *const str); int main(void) { char str[SIZE] = "H3ll0 W0rld! 2025"; cout << "Before: " << str << endl; tripleDigit(str); cout << "After: " << str << endl; return 0; } // Con puntatori char *tripleDigit(char *const str) { int len = strlen(str); for (char *j = str; j - str < len && len + 2 < SIZE - 1; j++) { if (isdigit(*j)) { if (len + 2 >= SIZE) break; memmove(j + 3, j + 1, len - (j - str) + 1); *(j + 1) = *j; *(j + 2) = *j; len = len + 2; j = j + 2; } } return str; } /* Senza puntatori char *tripleDigit(char *const str) { int len = strlen(str); for (int j = 0; j < len && len + 2 < SIZE - 1; j++) { if (isdigit(str[j])) { if (len + 2 >= SIZE) break; for (int k = len; k >= j; k--) { str[k + 2] = str[k]; } str[j + 1] = str[j]; str[j + 2] = str[j]; len = len + 2; j = j + 2; } } return str; } */