forked from CPRO-Session1/Assignment4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringfreq.c
More file actions
38 lines (27 loc) · 738 Bytes
/
Copy pathstringfreq.c
File metadata and controls
38 lines (27 loc) · 738 Bytes
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
/* Yael Kelmer.
This code takes a user inputed string and counts the amount of times each letter shows up in the string. */
#include <stdio.h>
#include <string.h>
int main ()
{
printf ("Please type in the letters you want in your string\n");
char userString [100];
fgets (userString, sizeof(userString), stdin);
int stringLength = strlen (userString);
userString [stringLength - 1] = '\0';
stringLength -= 1;
int ASCIIarray [128];
int i;
for (i = 0; i < 128; i++) {
ASCIIarray [i] = 0;
}
for (i = 0; i < stringLength; i++) {
char letter = userString [i];
ASCIIarray [(int) letter] += 1;
}
for (i = 0; i < 128; i++) {
if (ASCIIarray [i] > 0) {
printf ("%c = %d\n", (char) i, ASCIIarray [i]);
}
}
}