int main()
{
int num,i,j,k,smallindex;
cout<<"Enter the number for which you want to enter the names"<<endl;
scanf("%d",&num);
char lastname[num][25];
char firstname[num][25];
char name[num][50];
for(i=0;i<num;i++)
{
cout<<"Enter the last name followed by first name separated by a comma"<<endl;
scanf("%s",name[i]);
j=0;
k=0;
while(name[i][j]!=',')
{
lastname[i][j]=name[i][j];
j++;
}
j++;
while(name[i][j]!='\0')
{
firstname[i][k++]=name[i][j];
j++;
}
}
for(i=0;i<num;i++)
{
for(j=i+1;j<num;j++)
{
if(strcmp(firstname[j],firstname[i])<0)
{
smallindex=j;
}
else
{
if(strcmp(firstname[j],firstname[i])==0)
{
if(strcmp(lastname[j],lastname[i])<0)
smallindex=j;
}
}
}
swap(name[i],name[smallindex]);
}
return 0;