Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define CHARS 26
- #define LEN 1000
- void strLowerCase(char str[]) {
- for ( ; *str; str++ ) {
- if ( *str >= 'A' && *str <= 'Z' ) {
- *str += 32;
- }
- }
- }
- int main() {
- FILE *in = fopen("task.in", "r");
- FILE *out = fopen("task.out", "w");
- char str[LEN];
- int counters[CHARS];
- int len = 0;
- for ( int i = 0; i < CHARS; i++ ) {
- counters[i] = 0;
- }
- for ( int i = 0; fscanf(in, "%c", &str[i]) == 1; i++ ) {
- if ( str[i] != '\n' ) {
- len += 1;
- }
- }
- strLowerCase(str);
- for ( int i = 0; i < len && str[i] != EOF; i++ ) {
- int temp = str[i];
- temp = str[i] - 97;
- counters[temp] += 1;
- }
- for ( int i = 0, j = 97; i < CHARS; i++, j++ ) {
- if ( counters[i] > 0 ) {
- fprintf(out, "%c %d\n", j, counters[i]);
- }
- }
- fclose(in);
- fclose(out);
- return 0;
- }
Add Comment
Please, Sign In to add comment