title: How i can sort struct by characters in C?
body: <p>I used the strategy to sort struct by numbers , but this strategy does not work .</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #define MAX 1000
  
  typedef struct person_{
      char name[100];
      int age;
  }person;
  
  void scan_person(person *ptr);
  void print_ind(person p);
  
  int name_index_min(person *ptr, int N, int st);
  
  void swap(person *x, person *y);
  
  void sort_name_as(person *ptr, int N);
  void sort_name_ds(person *ptr, int N);
  
  int main () {
      person individulas[MAX];
      int n_ind;
  
      puts("Enter Number of people:");
      scanf("%d",&amp;n_ind);
      for (int i = 0; i &lt; n_ind; i++)
          scan_person(individulas + i);
  
      printf("\n");
  
      sort_name_as(individulas,n_ind);
      for (int i = 0; i &lt; n_ind; i++)
          print_ind(individulas[i]); 
  
      puts("\n");
  
      sort_name_ds(individulas,n_ind);
      for (int i = 0; i &lt; n_ind; i++)
          print_ind(individulas[i]);   
  
      printf("\n"); 
        return 0;
  }   
  
  void scan_person(person *ptr){
  
      printf("\nEnter Name &amp; Surename :");
      scanf("\n%99[^\n]", ptr-&gt;name);
  
      printf("Enter Age :");
      scanf ("%d%*c", &amp;(ptr-&gt;age));
      printf("\n");
  }
  void print_ind(person p){
      printf("%s %d  ", p.name, p.age);
  }
  int name_index_min(person *ptr, int N, int st){
  
      int min = st;
      for (int i = st+1; i &lt; N; i++)
          if(ptr[i].name &lt; ptr[min].name)
              min = i;
      return min;
  }
  int name_index_max(person *ptr, int N, int st){
  
      int max = st;
      for (int i = st+1; i &lt; N; i++)
          if(ptr[i].name &gt; ptr[max].name)
              max = i;
      return max;
  }
  
  void swap(person *x, person *y){
      person temp = *x;
      *x = *y;
      *y = temp;
  }
  
  void sort_name_as(person *ptr, int N){
      int aux;
      for (int i = 0; i &lt; N-1; i++){
          aux = name_index_min(ptr, N, i);
          if (aux != i)
              swap(ptr + i, ptr + aux);
      }
  }
  
  void sort_name_ds(person *ptr, int N){
      int aux;
      for (int i = 0; i &lt; N-1; i++){
          aux = name_index_max(ptr, N, i);
          if (aux != i)
              swap(ptr + i, ptr + aux);
      }
  }
  </code></pre>
  
  <p>Here is example:  </p>
  
  <p>Input:</p>
  
  <p>Enter Number of people:3  </p>
  
  <p>Enter Name &amp; Surename :Jeffrey L. Davis<br>
  Enter Age :80  </p>
  
  <p>Enter Name &amp; Surename :Yaseen Nur al Din Khoury<br>
  Enter Age :80  </p>
  
  <p>Enter Name &amp; Surename :Joeri Ong<br>
  Enter Age :80  </p>
  
  <p>Output:</p>
  
  <p>Joeri Ong  80  Jeffrey L. Davis 80  Yaseen Nur al Din Khoury 80  //ascendig order  </p>
  
  <p>Yaseen Nur al Din Khoury 80  Jeffrey L. Davis 80  Joeri Ong  80 //descendig order </p>