ADT
        aaron-thesis
        arm-eh
        ast-experimental
        cleanup-dtors
        deferred_resn
        demangler
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        new-env
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
        resolv-new
        with_gc
      
      
        
          | Last change
 on this file since 274ce8c was             9c14ae9, checked in by Rob Schluntz <rschlunt@…>, 9 years ago | 
        
          | 
add thesis source
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            699 bytes | 
      
      
| Line |  | 
|---|
| 1 | #include <stdio.h> | 
|---|
| 2 | #include <ctype.h> | 
|---|
| 3 |  | 
|---|
| 4 | int 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 |  | 
|---|
| 20 | void 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 |  | 
|---|
| 26 | int main() { | 
|---|
| 27 | dothing("hello"); | 
|---|
| 28 | dothing("hello, world!"); | 
|---|
| 29 | dothing("aaabbbba"); | 
|---|
| 30 | dothing(""); | 
|---|
| 31 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.