title: A program that displays the characters which appeared least/most often
body: <p>I've just written the code which is supposed to display the most/least (depending on a switch choice) appearing character. It has to work with standard input, that is from keyboard as well as with a text file. It's crucial for this program to show all char that appeared most often. For example in the input "abbcc" it should display b and c.
  It runs, but it doesn't show characters. The question is: why?</p>
  
  <p>Here's the code:</p>
  
  <p>a) main</p>
  
  <pre><code>int main (int argc, char *argv[]) {
      int string;
      int allChars[256] = {0};
      while ( (string=getchar())!=EOF ) 
          allChars[string]++;
      if (argc &lt; 2)
          mostOften(allChars);
      else {
          switch (argv[1][1]) {
          case 'm': case 'M':
              mostOften(allChars);
              break;
          case 'l': case 'L':
              leastOften(allChars);
              break;
          default:
              mostOften(allChars);
              break;
          } //switch
      } // else
  } // main
  </code></pre>
  
  <p>b) sf.c</p>
  
  <pre><code>void mostOften(int *s) {
      int i, j;
      int max[256] = {0} ;
      int max_count = 1;
      for (i=0; i&lt;256; i++) {
          if (s[i]) {
              if (s[i] &gt; max_count) {
                  for (j=0; j&lt;256; j++)
                      max[j]=0;
                  max[i]=1;
                  max_count = s[i];
              } // 2nd_if
              else if (s[i] == max_count)
                  max[i]=1;
              else
                  continue;
          } // 1st_if
      } //1st_for
      printf("The most appearing characters are: ");
      for (i=0; i&lt;256; i++) {
          if (max[i])
              putchar(s[i]);
      } //2nd_for
  }
  
  void leastOften(int *s) {
      int i, j;
      int min[256] = {0} ;
      int min_count = 1000;
      for (i=0; i&lt;256; i++) {
          if (s[i]) {
              if (s[i] &lt; min_count) {
                  for (j=0; j&lt;256; j++)
                      min[j]=0;
                  min[i]=1;
                  min_count = s[i];
              } // 2nd_if
              else if (s[i] == min_count)
                  min[i]=1;
          } // 1st_if
      } //1st_for
      printf("The least appearing characters are: ");
      for (i=0; i&lt;256; i++) {
          if (min[i])
              putchar(s[i]);
      } //2nd_for
  }
  </code></pre>
  
  <p>Thank you.</p>
  
  <p>EDIT1: deleted the mistake in the description
  EDIT2: changed from putchar(min[i]), putchar(max[i]) to putchar(s[i])</p>