short the string in alphabatical order

#include<stdio.h>
#include<string.h>
void main()
{
  int n,i,k=0,j;
  char temp[20];
  printf("how many cities you want to insert in ");
  scanf("%d",&n);
  char city[n][20];
  char cty[n][20];
  printf("enter the name of cities\n");
  for(i=0;i<n;i++)
  {
   scanf("\n%s",city[i]);
  }
  for(i=0;i<n;i++)
  {
   printf("\n%s",city[i]);
  }
  for(i=65;i<=122;i++)
  {
      for(j=0;j<n;j++)
      {
          if(city[j][0]==i)
          {
            strcpy(cty[k],city[j]);
            k++;
          }
      }
  }
  printf("after shorting\n");
  for(i=0;i<n;i++)
  {
   printf("\n%s",cty[i]);
  }
}


Comments

Popular posts from this blog

BYTE STUFFING PROGRAM USING C

Rotate a matrix 270 degree AntiClockWise

Finding the length of connected cells of 1's (regions) in an matrix of 1's and 0's