School-Coding-Cpp/sfusi/es4G.cpp

46 lines
757 B
C++

/*
Nome: Mario
Cognome: Montanari
Classe: 3AIN
Data: 07/03/2025
es4G: Scrivere una funzione che, ricevuta in input una
stringa, ne rimuova tutti i caratteri non alfabetici.
Prototipo richiesto:
char *removeexceptalpha(char * const str);
Esempio: "12 ottobre 1492" -> "ottobre"
*/
#include <iostream>
#include <cctype>
#define SIZE 100+1
using namespace std;
char *removeexceptalpha(char * const str);
int main(void) {
char str[SIZE];
cin.getline(str, SIZE);
cout << removeexceptalpha(str);
return 0;
}
char *removeexceptalpha(char * const str) {
int j = 0;
for (int i = 0; str[i] != '\0'; i++) {
if (isalpha(str[i])) {
str[j] = str[i];
j++;
}
}
str[j] = '\0';
return str;
}