43 lines
674 B
C++
43 lines
674 B
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 07/03/2025
|
|
|
|
es1D: Scrivere una funzione che, ricevuta una
|
|
stringa, ne restituisca il numero di cifre
|
|
Prototipo richiesto:
|
|
unsigned digitscount(const char *str);
|
|
Esempio:
|
|
"25dic2018" ? 5
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
#define SIZE 100+1
|
|
|
|
using namespace std;
|
|
|
|
unsigned digitscount(const char *str);
|
|
|
|
int main(void) {
|
|
char str[SIZE];
|
|
|
|
cin.getline(str, SIZE);
|
|
|
|
cout << digitscount(str);
|
|
|
|
return 0;
|
|
}
|
|
|
|
unsigned digitscount(const char *str) {
|
|
int contaDigits = 0;
|
|
|
|
for (int i = 0; str[i] != '\0'; i++) {
|
|
if (isdigit(str[i])) {
|
|
contaDigits++;
|
|
}
|
|
}
|
|
|
|
return contaDigits;
|
|
} |