Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #define MAX_STR 2
- #define ALPHA_LEN 26
- int main(void) {
- short int sumdigit = 0;
- short int alpha[ALPHA_LEN] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- char s[2];
- int i;
- FILE *f;
- f = fopen("challenge9_list.txt", "r");
- while (fscanf(f, "%s", s) != EOF) {
- if (isdigit(s[0])) sumdigit += (short) s[0] - (short) '0';
- else if (isalpha(s[0]))
- if (islower(s[0])) alpha[(short) s[0] - (short) 'a']++;
- }
- fclose(f);
- printf("Sum = %hd\n", sumdigit);
- for(i=0; i < ALPHA_LEN; i++) {
- if (alpha[i] != 0)
- printf("%c = %hd\n", (char) (i + (short) 'a'), alpha[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment