0
#include <stdio.h>
#include <conio.h>
#include <string.h>

main() {
    char s[200];
    scanf("%s", &s);

    int counter[255];
    int n = sizeof(counter) / sizeof(counter[0]);
    for (int i = 0; i < n; i++) {
        counter[i] = 0;
    }
    for (int i = 0; i < strlen(s); i++) {
        if (s[i] == 32) {
            break;
        }
        int temp = (int)s[i];
        counter[temp]++;
    }

    for (int j = 0; j < n; j++)
        if (counter[j] > 0) {
            printf("There are %d occurence of %c\n", counter[j], j);
        }
    }

This a simple program that counts how many times a character appears in a string. It works well if the input is a single word(no spaces). I know that the ASCII value for space is 32 and it should appear, but it doesn't.

chqrlie
  • 131,814
  • 10
  • 121
  • 189
nhick
  • 1

0 Answers0