source: doc/rob_thesis/examples/tuples/mrv_2.c @ bff09c8

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since bff09c8 was 9c14ae9, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

add thesis source

  • Property mode set to 100644
File size: 699 bytes
Line 
1#include <stdio.h>
2#include <ctype.h>
3
4int most_frequent(const char * str, char * ret_ch) {
5  char freqs [26] = { 0 };
6  int ret_freq = 0;
7  for (int i = 0; str[i] != '\0'; ++i) {
8    if (isalpha(str[i])) {        // only count letters
9      int ch = tolower(str[i]);   // convert to lower case
10      int idx = ch-'a';
11      if (++freqs[idx] > ret_freq) {  // update on new max
12        ret_freq = freqs[idx];
13        *ret_ch = ch;
14      }
15    }
16  }
17  return ret_freq;
18}
19
20void dothing(const char * str) {
21  char ch;
22  int freq = most_frequent(str, &ch);
23  printf("%s -- %d %c\n", str, freq, ch);
24}
25
26int main() {
27  dothing("hello");
28  dothing("hello, world!");
29  dothing("aaabbbba");
30  dothing("");
31}
Note: See TracBrowser for help on using the repository browser.