Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <stdlib.h>
- int *count(FILE *in) {
- int i, c;
- int *counter = (int *) malloc(26 * sizeof(int));
- for (i = 0; i < 26; i++) counter[i] = 0;
- while ((c = fgetc(in)) != EOF) {
- if (isupper(c)) {
- counter[c - 'A']++;
- continue;
- }
- if (islower(c)) {
- counter[c - 'a']++;
- continue;
- }
- }
- return counter;
- }
- int main(int argc, char **argv) {
- FILE *in = fopen(argv[1], "r");
- int *counter = count(in);
- fclose(in);
- int i;
- for (i = 0; i < 26; i++) printf("%c %d\n", i + 'A', counter[i]);
- free(counter);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement