
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

/* Prof. Torino / /Legge un nome e stampa il numero di occorrenze dei caratteri presenti nel nome stesso*/ #include
#define DIM 80 int main() { char testo[DIM]; char carattere; int occorrenze[DIM]; // creo un array per accogliere le occorrenze int i,j; /* leggi stringa nome */ printf("Inserisci una stringa:\n"); scanf("%s", testo); /* calcola la lunghezza del nome con la funzione strlen()*/ int lung= strlen(testo); // si può utilizzare in altenativa a testo[j] != '\0' nel ciclo for /* inizializza a zero l'array delle occorrenze*/ for (j = 0 ; j<=lung; j++){ occorrenze[j]= 0 ; } // doppio ciclo for per confrontare la singola lettera con tutte le altre for (j = 0 ; testo[j] != '\0'; j++){ for (i = 0 ; testo[i] != '\0'; i++) { carattere=testo[j]; if (testo[i] == carattere) occorrenze[j]++; // incremento delle occorrenze } } // visualizzo i risultati for (j = 0 ; j