how do you ascend/descend strings? any errors?

I have been having a huge amount of difficulty in C, when in C++ it is much simpler to sort out the program.
here is my algorithm:
#include <stdio.h>
#define SIZE 50
#include <stdlib.h>
#include <string.h>
void swap(char *, char *);

int main( void )
{
char *x[10];
x[0]="Charrot";
x[1]="Thomson";
x[2]="Camelot";
x[3]="Albert";
x[4]="Ann";
x[5]="Alice";
x[6]="Mary";
x[7]="Jean";
x[8]="James";
x[9]="Thor";

int i=0;
int j=0;
char *tmp;
tmp=NULL;

for(i = 0; i < 10; ++i)
{
for(j = i + 1; j < 10; ++j)
{
if(strcmp(x[i], x[j]) > 0)
swap(x[i], x[j]);
//tmp=x[i];
//x[i]=x[j];
//x[j]=tmp;
}
}

printf( "\nNames in Ascending order\n" );
for ( i = 0; i < 10; i++ ) {
printf( "%s \n", x[i] );
}
printf( "\n" );
return 0;
}
void swap(char **p, char **q) {
char *tmp;

tmp = *p;
*p = *q;
*q = tmp;
}

Please help me ASAP, thank you
Your prototype void swap(char *, char *); is different from the header of difinition
void swap(char **p, char **q). The latter is correct.

Invoke swap as follows: swap(&x[i], &x[j]);
Thank you for the reply but when i run it it shows 3 errors, and 1 is on the
int main(void)
and i tried changing the & however still wouldn't run.
when changing &
it says
[Error] C:\C-Free Standard\temp\Untitled1.cpp:31: passing `char **' as argument 1 of `swap(char *, char *)'
Last edited on
You didn't read the post closely.

melkiy said that your prototype of swap (line 5) is wrong, and you should correct it.
owh i c thank you, and sorry .. perhaps an error with me and my c free then
Topic archived. No new replies allowed.