title: sort words alphabeticaly in C
body: <p>I have a problem, my program in C have to find words with N letters, count them and sort them in lexicographical order and save them to an another file. How could I sort the words in alphabetical order?</p>
  
  <p>this is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;stddef.h&gt;
  #include &lt;string.h&gt;
  
  int main()
  {
  FILE *r, *fp;
  char ch[100],t[100];
  int n,i,j,x=0;
  
  
  r=fopen("text.txt","r");
  fp=fopen("text2.txt","w");
  fgets(ch, 100, r);
  
  
  char *start;
  int len;
  char *s = ch;
  char *p = s;
  printf("Give the length of word: ");
  scanf("%d",&amp;n);
  printf("\n\nWords with %d letters: \n\n",n);
      while (*p) {
  
          while (*p &amp;&amp; isspace(*p))
              ++p;
          start = p; 
  
          while (*p &amp;&amp; !isspace(*p))
              ++p;
  
          len = p - start;
  
          if (len == n) {
  
              printf("%.*s\n", len, start);
                x++;
  
              fprintf(fp,"%.*s",len, start);
  
          }    
      }      
  
  
  printf("\nNumber of words: %d ",x);
  fclose(fp);
  
  
  
  getch();      
  fclose(r);  
  } 
  </code></pre>