Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- char ch,ch_pre;
- int righe=1,parole=0,caratteri=0;
- ch_pre='\n';
- printf("Inserisci testo (per terminare EOF)\n");
- while((ch=getchar())!=EOF){
- switch(ch){
- case '\n':
- if((ch_pre=='\n')||(ch_pre=='\t')||(ch_pre==' ')){
- righe++;
- ch_pre=ch;
- break;
- }
- righe++;
- parole++;
- ch_pre=ch;
- break;
- case '\t':
- if((ch_pre=='\n')||(ch_pre=='\t')||(ch_pre==' ')){
- ch_pre=ch;
- break;
- }
- parole++;
- ch_pre=ch;
- break;
- case ' ':
- if((ch_pre=='\n')||(ch_pre=='\t')||(ch_pre==' ')){
- ch_pre=ch;
- }
- parole++;
- ch_pre=ch;
- break;
- default:
- caratteri++;
- ch_pre=ch;
- break;
- }
- }
- /* per come ho scritto il codice se inserisco EOF senza inserire come ultimo carattere ' ' o ' \n' o '\t' non viene
- contata l'ultima parola e perciò:*/
- if((ch_pre!='\n')||(ch_pre!='\t')||(ch_pre!=' ')){
- parole++;
- }
- printf("\n");
- printf("Numero righe :%d ; Numero parole :%d ; Numero caratteri :%d \n",righe,parole,caratteri);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement