Advertisement
Fran0031

Ejercicio 18 Boletín 3

Nov 22nd, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int num_between(char text[], int c1, int c2) {
  5.     int cnt, total;
  6.     int code;
  7.  
  8.     for (total = cnt = 0; cnt < strlen(text); cnt++) {
  9.         code = (int) text[cnt];
  10.         if (code >= c1 && code <= c2)
  11.             total++;      
  12.     }  
  13.  
  14.     return total;
  15. }
  16.  
  17. int num_lower(char text[]) {
  18.     return num_between(text, (int) 'a', (int) 'z');
  19. }
  20.  
  21. int num_upper(char text[]) {
  22.     return num_between(text, (int) 'A', (int) 'Z');
  23. }
  24.  
  25. int num_digit(char text[]) {
  26.     return num_between(text, (int) '0', (int) '9');
  27. }
  28.  
  29. int main() {
  30.     char text[100];
  31.  
  32.     printf("Introduce un texto: ");
  33.     scanf("%s", text);
  34.  
  35.     printf("%s contiene:\n", text);
  36.     printf("\t%d minusculas\n", num_lower(text));
  37.     printf("\t%d mayusculas\n", num_upper(text));
  38.     printf("\t%d letras\n", num_lower(text) + num_upper(text));
  39.     printf("\t%d digitos\n", num_digit(text));
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement