-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCppLetterCounter.cpp
48 lines (42 loc) · 1011 Bytes
/
CppLetterCounter.cpp
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
#include <iostream>
int getCount(char* string, char _c) {
char* t;
int count = 0;
for (t = string; (*t != '\0') && (*t != '\n'); t++) {
if (*t == _c) { count++; }
}
return count;
}
bool contains(char* charArray, char* _c) {
char* t;
for (t = charArray; (*t != '\0') && (*t != '\n'); t++) {
if (*t == *_c) {
return true;
}
}
return false;
}
int main(int argc, char* argv[])
{
char alreadyCounted[100];
char string[100];
int countOffset = 0;
if (argc > 1) {
for (int i = 0; i < 100; i++) {
string[i] = argv[1][i];
}
}
else {
printf("input string: ");
fgets(string, 100, stdin);
}
char* t;
for (t = string; (*t != '\0') && (*t != '\n'); t++) {
if (!contains(alreadyCounted, t)) {
printf("%c [0x%X]: %d\n", *t, *t, getCount(string, *t));
alreadyCounted[countOffset] = *t;
countOffset++;
}
}
getchar();
}