STRING SORT- Getting Wrong Answer in Test Case

My TestCases are failing in this code, could not understand why? Can you please debug and tell me where am I going wrong.
#include
#include
#include
#include<string.h>
using namespace std;

int main()
{
int n;
cin >> n;
char str[n][20];
for(int i=0;i<n;i++)
cin>> str[i];
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(strcmp(str[i],str[j]))
{
char s[20];
strcpy(s,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],s);
}

    }
}
for(int i=0;i<n-1;i++)
{
    int count=0;
    for(int j=0;j<strlen(str[i]);j++)
    {
        if(str[i][j]==str[i+1][j])
        {
            count++;
        }
    }
    if(count==strlen(str[i]))
    {
        char s[20];
        strcpy(s,str[i+1]);
        strcpy(str[i+1],str[i]);
        strcpy(str[i],s);
    }
}
for(int i=0;i<n;i++)
{
    cout<<endl<<str[i];
}
return 0;

}

First of all these type of questions should be solved with comparators and you are using O(n^2)
and this should be solved in O(n log n).
U can refer my code for its code in comparators STL
https://ide.codingblocks.com/s/69386

if u dont know comparator or want to learn about it . ping me (Anubhav )or Tushar after 10 pm through whatsapp group

Hi Anubhav,
Can you please add me to the Whatsapp Group.
9869690406

Provide Your registered email id in online courses??

[email protected]

@sanjeetboora Can u add him to whatsapp group.
Thanx

Hi Tirth,

You must have got an email in which the WhatsApp link for your batch is mentioned.