0
//program to print the sentences in lexicographical order
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j;
char a[n][20],temp[20];

printf("enter the number of strings");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
    printf("enter the string%d",i);
    fgets(a[i],sizeof(a[i]),stdin);
}
for(i=1;i<n;i++)
{
    for(j=i+1;j<=n;j++)
    {
        if(strcmp(a[i],a[j])>0)
        {
            strcpy(temp,a[i]);
            strcpy(a[i],a[j]);
            strcpy(a[j],temp);
            
        }
        
    }
}
printf("In lexicographical order");
for(i=1;i<=n;i++)
{
    fputs(a[i],stdout);
}
return 0;
}

输出:

enter the number of strings4
enter the string1enter the string2raja
enter the string3sekar
enter the string4hari
In lexicographical order
hari
raja
sekar

我已经包括了输入和输出。在它显示的输出屏幕中enterthestring1enterthestring2,我只需要得到一句话enterthestring1。什么是错误哥们

4

0 回答 0