Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to arrange Names in Alphabetical order

Status
Not open for further replies.

Parth86

Member
I am looking help to arrange names in alphabetical order. first user check how many names are there and then arrange in alphabetical order

I found this program this program arrange number in ASCENDING ORDER. I don't have idea how to do it for arranging name alphabetical order. What changes I have to do in program ?
C:
#include <stdio.h>

int main(void)
{
    int a[10], i=0, j=0, n, t;

    printf ("\n Enter the no. of elements: ");
    scanf ("%d", &n);
    printf ("\n");

    for (i = 0; i <n; i++)
    {
        printf ("\n Enter the %dth element: ", (i+1));
        scanf ("%d", &a[i]);
    }

    for (j=0 ; j<(n-1) ; j++)
    {
        for (i=0 ; i<(n-1) ; i++)
        {
            if (a[i+1] < a[i])
            {
                t = a[i];
                a[i] = a[i + 1];
                a[i + 1] = t;
            }
        }
    }

    printf ("\n Ascending order: ");
    for (i=0 ; i<n ; i++)
    {
        printf (" %d", a[i]);
    }

      /* indicate successful completion */
      return 0;
}
 
I found this program this program arrange number in ASCENDING ORDER. I don't have idea how to do it for arranging name alphabetical order. What changes I have to do in program ?
* Convert the Name(s) to an ASCII string.
* Sort on the First ASCII character (which is a number)
* Repeat for the 2nd, 3rd........
That should do the sorting.
 
Don't upper and lower case create a problem? For example, del Castillo. Seems like you need a rule for name capitalization or merge the sets. The offset is 0x20 (.32) so there should be no ambiguity.

John
 
Is there any way to do it without qsort(); or with out string.h file ?
Yes! but whatever you come up with qsort() will do it much better.... As John has already said! You have to Uppercase everything, whilst remembering how they are initially.. You have to do each character... Take Justin and Justine for example... Two names that all the elements need checking...

Minefield.... Someone has done the hard part!!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top