Order Strings in Dictionary order in C

Code Snippets 4 U
#include < stdio.h > 
#include < stdlib.h > 
#include < string.h >

  int main() {
    char a[][100] = {
      {
        "C"
      },
      {
        "C++"
      },
      {
        "PHP"
      },
      {
        "Java"
      },
      {
        "PHP"
      },
      {
        "Spring"
      },
      {
        "Python"
      },
      {
        "Scala"
      },
      {
        "Ruby"
      },
      {
        "Perl"
      }
    };

    for (int i = 0; i < 10; i++) {
      for (int j = i + 1; j < 10; j++) {
        if (strcmp(a + i, a + j) > 0) {
          char str[100];
          strcpy(str, a + i);
          strcpy(a + i, a + j);
          strcpy(a + j, str);
        }
      }
    }

    for (int i = 0; i < 10; i++) {
      printf("%s\n", a + i);
    }
    return 0;
  }

Leave a Reply

Your email address will not be published. Required fields are marked *

six + one =