Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int num_between(char text[], int c1, int c2) {
- int cnt, total;
- int code;
- for (total = cnt = 0; cnt < strlen(text); cnt++) {
- code = (int) text[cnt];
- if (code >= c1 && code <= c2)
- total++;
- }
- return total;
- }
- int num_lower(char text[]) {
- return num_between(text, (int) 'a', (int) 'z');
- }
- int num_upper(char text[]) {
- return num_between(text, (int) 'A', (int) 'Z');
- }
- int num_digit(char text[]) {
- return num_between(text, (int) '0', (int) '9');
- }
- int main() {
- char text[100];
- printf("Introduce un texto: ");
- scanf("%s", text);
- printf("%s contiene:\n", text);
- printf("\t%d minusculas\n", num_lower(text));
- printf("\t%d mayusculas\n", num_upper(text));
- printf("\t%d letras\n", num_lower(text) + num_upper(text));
- printf("\t%d digitos\n", num_digit(text));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement