мы должны ввести n строк и отсортировать их в порядке возрастания, когда сортировка выполняется по длине, а также по значениям ascii. пожалуйста, помогите .... есть тестовый образец случай: нет строк 5 Omar яблока банана муравья кошкасортировка строк с ascii и длиной строк
выхода должен быть: муравья кошка Omar яблоко банан
enter code here:
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,l,m,j;
char str[20][20],temp[20],temp2[20][20];
printf("enter no of strings\n");
scanf("%d",&n);
// string is given as input
for(i=0; i<n; i++)
{
fflush(stdin);
scanf("%s",str[i]);
l=strlen(str[i]);
printf("len is %d\n",l);
}
//sorting on the basis of length
for(i=0; i<=n; i++)
for(j=i+1; j<=n; j++)
{
if(strlen(str[i])>strlen(str[j]))
{
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
//sorting on the basis of ascii values
for(i=0; i<n; i++)
{
if(l==m)// spcl condition
{
printf("\ncheck",l,m);
for(j=0; j<strlen(str[i]); j++)
{
if(strcmp(str[j][i],str[j][++i])>0)
{
strcpy(temp2[20],str[i]);
strcpy(str[i],str[++i]);
strcpy(str[++i],temp2[20]);
}
}
}
else// default condition
{
strcpy(temp2[20],str[i]);
strcpy(str[i],str[++i]);
strcpy(str[++i],temp2[20]);
}
}
//display each string
printf("the strings are\n");
for(i=0; i<n; i++)
{
printf("%s",str[i]);
printf("\n");
}
return 0;
}