#include<stdio.h>
#include<conio.h>
#include<string.h>
int n;
char (*p)[40],*temp;
void Input();
void ABCsorting();
void Input()
{
printf("How many persons u want to input: ");
scanf("%d",&n);
p=(char*)malloc(n*40*sizeof(char));
temp=(char*)malloc(n*sizeof(char));
int i;
for(i=0; i<n ; i++)
{
printf("String %d: ",i+1);
fflush(stdin);
gets(p[i]);
}
printf("All strings before sorting: \n");
/*for(i=0; i<n ; i++)
{
printf(" %s\n",*(p+i) );
} */
for(i=0; i<n ; i++)
printf(" %s |",p[i]);
}
void ABCsorting()
{
int i,j;
for(i=0; i<n-1 ;i++)
for(j=i+1; j<n; j++)
{
if( strcmp((p+i),(p+j)) > 0 )
{
temp = (p+i);
(p+i) = (p+j);
(p+j) = temp;
}
/* if( strcmp(p[i], p[j]) > 0)
{
temp=p[i];
p[i]= p[j];
p[j]=temp;
}*/
}
printf("\nAfter Sorting: \n");
for(i=0; i<n ;i++)
printf(" %s |",p[i]);
}
int main()
{
Input();
ABCsorting();
getch();
return 0;
}
Please help me find the mistake in my above source code
Thanks a lot!