#include <stdio.h>
#include <stdlib.h>

main()
{
char a[30];
int i,j,n,temp;
printf("enter the limit: ");
scanf("%d",n);
printf("enter the string: ");
for(i=0;i<n;i++)
{
    scanf("%s",a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(strlen(a[i])>strlen(a[j]))
{

temp=a[j];
a[i]=a[j];
a[j]=a[i];
}
}
}
for(i=0;i<n;i++)
{
    printf("%d",a[i]);
}
}

compiler stops working here when executing the program but 0 errors

no iam asking about sorting now

variable a is an single dimensional array which will hold only one string. What you want is something like this: char a[20][30]; which is a 2d array that holds up to 20 strings, and each string can contain up to 30 characters (29 + null terminator).

no iam asking about sorting now

Maybe you should finish learning something before running off to learn something new, because you keep making the same mistakes.

no actually i soretd the words alphabhetically using the same method that worked perfectly see this

#include <stdio.h>
#include <stdlib.h>

void main()
{
    char name[10][10],temp[10];
    int i,j,n;
    printf("enter the limit : ");
    scanf("%d",&n);
    printf("enter the names: ");
    for(i=0;i<n;i++)
    scanf("%s",&name[i]);
    for(i=0;i<n-1;i++)
    for(j=i+1;j<n;j++)
    if(strcmp(name[i],name[j])>0)

    {
        strcpy(temp,name[i]);
        strcpy(name[i],name[j]);
        strcpy(name[j],temp);
    }

    printf("the sorted list is \n");
    for(i=0;i<n;i++)
    {
        printf("%s\n",name[i]);
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.