-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram189.c
More file actions
65 lines (51 loc) · 1.12 KB
/
Copy pathprogram189.c
File metadata and controls
65 lines (51 loc) · 1.12 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<stdio.h>
// Input : deRm2dfr
// Char : R
// Output : 2 (Correct)
// Input : Demo@23@re
// Char : @
// Output : 2
// Case inSensentice
int charFrequency(char *str,char ch)
{
int iCount = 0;
while(*str != '\0')
{
if((ch >= 'a') && (ch <= 'z')) // Small
{
if(*str == ch || *str == ch - 32)
{
iCount++;
}
}
else if((ch >= 'A') && (ch <= 'Z')) // Capital
{
if(*str == ch || *str == ch + 32)
{
iCount++;
}
}
else // Other(special char, digits and etc)
{
if(*str ==ch)
{
iCount++;
}
}
str++;
}
return iCount;
}
int main()
{
int iRet = 0;
char cValue = '\0';
char Arr[50] = {'\0'};
printf("Enter String :");
scanf("%[^'\n']s",Arr);
printf("Enter Charecter :");
scanf(" %c",&cValue);
iRet = charFrequency(Arr,cValue);
printf("%c occurs %d times\n",cValue,iRet);
return 0;
}