Thursday, March 21, 2013

C Language Example # 41 (2D) Two Dimension Character Array Sorting

C Language Example # 41 (2D) Two Dimension Character Array Sorting..

* Program will Sort two dimension character array(2D)
.
* In program we have set some string, program will automatically sort this array.

//Written by : Latest Technology Guide
//Title : C Language Example # 41 (2D) Two Dimension Character Array Sorting.


#include <stdio.h>
#include <conio.h>
#include <string.h>
#define NAME 5
#define SIZE 10
void main()
{
    clrscr();
    char ch[NAME][SIZE]={"Ram","Sita","Lakhan","Ramji","Laxman"};
    int i,j;

    char dummy[SIZE];

    for(i=0;i<NAME;i++)
    {
        for(j=i+1;j<NAME;j++)
        {
            if(strcmp(ch[i],ch[j])>0)
            {
                strcpy(dummy,ch[j]);
                strcpy(ch[j],ch[i]);
                strcpy(ch[i],dummy);
            }
        }

    }

    for(i=0;i<NAME;i++)
        puts(ch[i]);

    getch();

}



Output:


--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 41 (2D) Two Dimension Character Array Sorting.

* Program will sort two dimension character array.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

1 comment: