/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#define N 100
int get_index(char c, char *sym)
{
int len = strlen(sym);
for(int i = 0; i < len; i++)
{
if (sym[i] == c)
return (i);
}
return (-1);
}
int main()
{
char buf[N] = {};
char sym[N] = {};
int count[N] = {};
int len;
int last_index = 0;
printf("Enter: ");
fgets(buf, N, stdin);
len = strlen(buf) - 1;
for(int i = 0; i < len; i++)
{
int current = get_index(buf[i], sym);
if (current < 0)
{
sym[last_index] = buf[i];
count[last_index] = 1;
last_index++;
}
else
count[current] += 1;
}
for(int i = 0; i < strlen(sym); i++)
printf("%c - %2d\n", sym[i], count[i]);
return 0;
}