title: Segmentation fault (core dumped) - how to fix my code?
body: <p>The program finds a char with the smallest ascii code in a string and outputs it. My problem is in message: Segmentation fault(core dumped). Why and Where does it occur? 
  Thanks for attention.  </p>
  
  <pre><code>#include &lt;stdio.h&gt;    
  #include &lt;string.h&gt;    
  #include &lt;stdlib.h&gt;    
  
  int main(void) {    
  
  char* str = NULL;    
  int* mincode = NULL;    
  int* count = NULL;    
  char* mincodeChar = NULL;
  
  
   str = (char *) malloc(50 * sizeof(char));
   mincode = (int *) malloc(1 * sizeof(int));
   count = (int *) malloc(1 * sizeof(int));
  
   if (NULL == str || NULL == mincode || NULL == count){
          printf("Alloc error");
          return EXIT_FAILURE;
      }
  
  fgets(str, 50, stdin);
  
  printf("your string: ");
  puts(str);
  
  *mincode = (int)(str[*count]);
  *mincodeChar = *(str + *count);
  
   for (*count = 0; str[*count] != '\0'; (*count)++) {
  
      if( (int)str[*count] &lt; (*mincode)) {
      (*mincode) = (int)str[*count];
      mincodeChar = (str + *count);
      printf("%c", *mincodeChar);
      }
  }
  
  printf("your character: ");
  printf("%c", *mincodeChar);
  
  free(str);
  free(mincode);
  free(count);
  
  return EXIT_SUCCESS;
  }
  </code></pre>