Question: Question 2. Sorting Strings Write your code to fill out a program so that it can sort predefined strings according to ascending order. Probably, you
Question 2. Sorting Strings
Write your code to fill out a program so that it can sort predefined strings according to ascending order. Probably, you will use library function strcmp (string.h) when comparing one string with another so as to decide which one is bigger/smaller. The program below is using pointer method. Check professors chapter8/chapter9 slides for how to use pointer array. Name your program file Hw5_q2_code.c.
Here is the program:
#include
#include
void sort(char *[], int);
int main(
{
char *name[] = {"College Station","Houston", "Dallas", "Austin", "San Antonio"};
int i, n=5;
sort(name,n);
printf("After sorting (Ascending): ");
for(i=0;i<=n-1;i++)
printf("%s ",name[i]);
return 0;
}
void sort(char *name[], int n)
{
char *temp;
/*filling with your own code You may use strcmp library function (from string.h) for comparation between two strings. */
}
Exemplify:
After sorting (Ascending):
Austin
College Station
Dallas
Houston
San Antonio
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
