#include <stdio.h>
#include <stdlib.h>
void swap(char *ap,char *bp,int x);
void compare(char *ap,char *bp);
int main()
{
int b,x,y,j,damn;
int i=0;
char info[13][20]=
{
"christina",
"victor",
"chris",
"chester",
"elta",
"kezia",
"bew",
"grace",
"mavis",
"tony",
"oat",
"adonique",
"ploy"
};
char *ap;
ap=info[i];
char *bp;
bp=info[i+1];
for(b=0; b<13; b++)
{
while(i<13)
{
compare(ap,bp);
i++;
}
for(y=0; y<13; y++)
{
printf("%s\n",info[y]);
}
return 0;
}
}
void compare(char *ap,char *bp)
{
int i=0;
int x;
int damn;
if(*ap==*bp)
{
int j=1;
while (*(ap+j)==*(bp+j))
{
if (*(ap+j) == '\0' && *(bp+j) == '\0')
{
damn=0;
break;
}
j++;
}
if (*(ap+j)<*(bp+j))
{
damn=1;
}
if (*(ap+j)>*(bp+j))
{
damn=-1;
}
}
if (*ap<*bp)
{
damn=1;
}
if (*ap>*bp)
{
damn=-1;
}
if (damn==-1)
{
while(*(ap+x) != '\0' || *(bp+x) != '\0')
{
swap(ap,bp,x);
x++;
}
}
}
void swap(char *ap,char *bp,int x)
{
char tmp[20];
for(x=0; x<19; x++)
{
printf("k");
*tmp=*ap;
*ap=*bp;
*bp=*tmp;
}
}
What I have tried:
i tried to print k in swap function but it didn't show