Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. char str[100];
  5. int i;
  6. int char_count=1;
  7. int word_count=0;
  8. int row_count=0;
  9.  
  10. int main()
  11. {
  12.     printf("Inserire del testo:\n");   
  13.    
  14.     for(i=0; i<100; i++)
  15.     {
  16.         scanf("%c",&str[i]);
  17.         char_count++;
  18.        
  19.         if(str[i]=='\n')
  20.         {
  21.             char_count--;
  22.         }
  23.  
  24.         if(str[i]==' '&&str[i+1]!='\n'&&str[i-1]!=' ','\0')
  25.         {
  26.             word_count++;
  27.         }
  28.  
  29.         if((row_count==0&&str[0]=='X')||(row_count!=0&&str[0]=='X'&&str[1]=='\n'))
  30.         {
  31.             exit(0);   
  32.         }
  33.  
  34.         if(str[i]=='\n')
  35.         {
  36.             break;
  37.         }  
  38.     }
  39.  
  40.     row_count++;
  41.  
  42.     printf("\nNumero di caratteri: %d\n", char_count-1);
  43.     printf("Numero di parole: %d\n", word_count);
  44.     printf("Numero di righe: %d\n\n",row_count);
  45.  
  46.     main();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement