Advertisement
luizaspan

Strings

Jun 22nd, 2015
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define n 50
  4.  
  5. int main(void)
  6. {
  7.     char f[n];
  8.     int i,k=0,g=0,d=0;
  9.  
  10.     printf("[máx 50 caracteres] ");
  11.     fgets(f,50,stdin);
  12.  
  13.     printf("%s \n",f);
  14.  
  15.     for (i=0;f[i] != '\0';i++)
  16.     {
  17.         if (tolower(f[i])=='a' || tolower(f[i])=='e' || tolower(f[i])=='i' || tolower(f[i])=='o' || tolower(f[i])=='u')
  18.             k++;
  19.     }
  20.  
  21.     for (i=0;f[i] != '\0';i++)
  22.     {
  23.         if (tolower(f[i])=='g' && tolower(f[i+1])=='a' && tolower(f[i+2])=='t' && tolower(f[i+3])=='o')
  24.             g=1;
  25.     }
  26.  
  27.     for (i=0;f[i] != '\0';i++)
  28.     {
  29.         if (tolower(f[i])=='d' && tolower(f[i+1])=='e')
  30.             d++;
  31.     }
  32.  
  33.     printf("Número de vogais na frase: %d. \n",k);
  34.  
  35.     if (g==1)
  36.         printf("A palavra \"gato\" está contida na frase. \n");
  37.  
  38.     else if (g==0)
  39.         printf("A palavra \"gato\" não está contida na frase. \n");
  40.  
  41.     printf("Frequência da palavra \"de\" na frase: %d. \n",d);
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement