c program to sort a string in alphabetic order

C program to sort a string in alphabetic order: For example if user will enter a string "programming" then output will be "aggimmnoprr" or output string will contain characters in alphabetical order.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
main()
{
      char string[100], ch, *pointer, *result, *temp;
      int c, length;
       printf("Enter a string\n");
      gets(string);
      length = strlen(string);
       temp = result = (char*)malloc(length+1);
       pointer = string;
       for ( ch = 'a' ; ch <= 'z' ; ch++ )
      {
          for ( c = 0 ; c < length ; c++ )
          {
              if ( *pointer == ch )
              {
                 *result = *pointer;
                 result++;
              }
              pointer++;
          }
          pointer = string;
      }
      *result = '\0';
       result = temp;
       strcpy(string, result);
       free(result);      
       printf("%s\n", string);
       return 0;
}