What i want is when the user presses D then the strings he/she inputted would be sorted descendingly like what i did with the ascending part and it works just fine but i don't know how to add the two.
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<string.h>
char a[50][50],*tmp,*tmp2;
int num,p,c,q,t,choice;
void main()
{
clrscr();
cout<<"Input number of data: ";
cin>>num;
for(int x=0;x<num;x++)
gets(a[x]);
cout<<"\n\nUnsorted data: ";
for(int y=0;y<num;y++)
cout<<a[y]<<",";
cout<<"\nHow would you like to sort these data [A]scending or [D]escending?";
p=num-1;
for(p;p>0;p--)
{
for(c=0;c<p;c++)
{
if(stricmp(a[c],a[c+1])>0) */all i know is that when i change it to < it would be sorted descendingly i dont know how to add both ascending and descending option */
{
strcpy(tmp,a[c]);
strcpy(a[c],a[c+1]);
strcpy(a[c+1],tmp);
}
}
}
choice=getch();
if(choice=='A' | choice=='a')
cout<<"\n Sorted data in ascending order: ";
for(int z=0;z<num;z++)
cout<<a[z]<<",";
getch();
}