**Updated code**

Code:

#include<stdio.h>
#include<conio.h>
void word_swap(char*,char*); /*I don't think I have written the definition of this function correctly*/
int main()
{
char temp[20],names[5][20];
int x,y,z;
for(x=0;x<5;x++)
{
printf("\nEnter a name :");
fgets(temp,20,stdin);
for(y=0;names[x][y]!='\0';y++)
{
names[x][y]=temp[y];
}
names[x][y]='\0';
}
for(x=0;x<5;x++)
{
for(z=x+1;z<5;z++)
{
for(y=0;names[x][y]!='\0'&& names[z][y] !='\0';y++)
{
if((int)names[x][y]>(int)names[z][y])
word_swap(&names[x][0],&names[z][0]);
}
}
}
for(x=0;x<5;x++)
{
printf("\n");
for(y=0;names[x][y]!='\0';y++)
printf("%c",names[x][y]);
}
getch();
return 0;
}
void word_swap(char*str1,char*str2)
{
int n=0;
char temp;
while(n!=2)
{
temp=*str1;
*str1=*str2;
*str2=temp;
str1++;
str2++;
if(*str1=='\0')
n++;
if(*str2=='\0')
n++;
}
}