To sort names in alphabetical order, we need a string array. We will store names into the string. Then we need to sort the names in the dictionary/alphabetical order.

After storing the names in the array. We use bubble sort to sort the array. Hence we perform two major operations in bubble sort :

  • Compare – We are comparing two names using strcmp(FirstString, SecondString ) method, which takes two string as parameters. It returns the difference of FirstString – SecondString.
  • Swap – We are using default swapping technique with the use of a temporary variable. The only difference is, in place of assigning value, we are copying the value of one string into another using strcpy(destinationString, SourceString ).

That’s all we are doing in the code below. And yeah we are also displaying array before and after Sorting.

Sort Name (String Array) Array in C

Output of Program

String array in C

If you have any doubt or if the code doesn’t work for you, then comment below your problem.

Leave a Reply

Close Menu