-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFreq.c
42 lines (32 loc) · 855 Bytes
/
Freq.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*******************************************************
Statement - Find a frequenct of character in string
Programmer - Vineet Choudhary
Written For - https://developerinsider.co
*******************************************************/
#include <stdio.h>
#include <string.h>
#include <conio.h>
void find_frequency(char [], int []);
void main()
{
char string[100];
int c, count[26] = {0};
clrscr();
printf("Input a string\n");
gets(string);
find_frequency(string, count);
printf("Character Count\n");
for (c = 0 ; c < 26 ; c++)
{
printf("%c \t %d\n", c + 'a', count[c]);
}
getch();
}
void find_frequency(char s[], int count[]) {
int c = 0;
while (s[c] != '\0') {
if (s[c] >= 'a' && s[c] <= 'z' )
count[s[c]-'a']++;
c++;
}
}