please help
im really stuck in my sorting
you see i need to make a program that asks the user 10 names of people then the array of names gets pass to another function where it is sorted in ascending or descending depending on what the user wants. that function doesn't return anything.
here's what i got so far:

# include <stdio.h>
# include <string.h>

void sort(char [10][10],int choice);

int main()
{
    int i,j,choice;
    char array[10][10];
    printf("Enter names");

    for(i=0;i<10;i++)
    {
        printf("\nName#%d:",i+1);
        gets(array[i]);
    }
    for(j=0;j<10;j++)
        puts(array[j]);
    printf("\nPress 1.Ascending\n2.Descending");
    scanf("%d",&choice);

    sort(array,choice);

    return 0;
}
void sort(char array[10][10], int choice)
{

    int i,k;
    if(choice==1)
    {

    }
}

In your previous thread you've already been suggested to use code tags, perhaps you missed it?
Anyway here's the link which will directly bring you to the page where the use of code tags is explained (read it, I'm sure that when you've read it you'll say: "Ohhh, was it that easy?")

P.S.: Instead of manually entering the bb-tags to include code, you could also just simply use the button labeled: (code).

# include <stdio.h>
# include <string.h>
# include <stdlib.h>


void sorting(char a[][10],int n);
int  main()
{
char s[10][10];
int i;


	for(i=0;i<10;i++)
	{
		printf("Enter name:");
		gets(s[i]);
	}


	sorting(s,10);
	printf("\nSorted Names\n");
	for(i=0;i<10;i++)
		{
		printf("%s\n",s[i]);
		}
return 0;
}

void sorting(char a[][10],int n)
{
	int i,j;
	int choice;
	char temp[10];

	printf("Choose\n1.Ascending\n2.Descending\n");
	scanf("%d",&choice);
		if(choice==1)
			{
				for(i=0;i<10;i++)
					{
						for(j=i+1;j<10;j++)
						{
							if(strcmp(a[j],a[i])<0)
								{
									strcpy(temp,a[i]);
									strcpy(a[i],a[j]);
									strcpy(a[j],temp);
								}
						}
					}
			 }
		else
		{

		}
}

now im stuck as to how to display it in decending order

Here's an assignment. Search why

gets(s[i]);

is a no no.

What is it that you are sorting the names by?

now im stuck as to how to display it in decending order

Well you've almost done it. Change the comparison in your strcmp() to be "greater than" (>) to sort the names in descending order. In addition to studying up on why gets() is a poor function (use fgets() instead), study up on the strcmp() function as well to understand why a "greater than" comparison will give you the names in descending order.

thank you guys i finally got it

and also about the get() and fgets() thank you for the correction

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.