Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

C program to sort a customer list in the alphabetical list

YASH PAL, 31 July 2024

In this tutorial, we are going to write a C Program to sort a customer list in the alphabetical list in C Programming with practical program code and step-by-step full complete explanation.

C program to sort a customer list in the alphabetical list

C Program to sort a customer list in the alphabetical list.

 
#include<stdio.h>
#include<conio.h>

#define CUSTOMERS 10

void main()
{
    char first_name[20][10], second_name[20][10], surname[20][10], name[20][20], telephone[20][10], dummy[20];

    int i,j;

    printf("Input names and telephone numbers");
    printf("?");

    for(i=0;i<CUSTOMERS;i++)
    {
        scanf("%s %s %s %s", first_name[i],second_name, surname[i], telephone[i]);

        strcpy(name[i], surname[i]);
        strcat(name[i], ",");

        dummy[0]=first_name[i][0];
        dummy[1]='';

        strcat(name[i],dummy);
        stcat(name[i],".");

        dummy[0]=second_name[i][0];
        dummy[1]='';

        strcat(name[i],dummy);
    }

    for(i=1;i<=CUSTOMERS-1;i++)
    for(j=1;j<=CUSTOMERS-1;j++)
        if(strcmp(name[j-1], name[j])>0)
        {
            strcpy(dummy,name[j-1]);
            strcpy(name[j-1],name[j]);
            strcpy(name[j],dummy);
            strcpy(dummy,telephone[j-1]);
            strcpy(telephone[j-1],telephone[j]);
            strcpy(telephone[j],dummy);
        }

        printf("CUSTOMERS LIST IN ALPHABETICAL ORDER");

        for(i=0;i<CUSTOMERS;i++)
            printf("%-20st%-10s",name[i],telephone[i]);
}

Output

 
Input names and telephone numbers
? anandamurugan 9486153102
Renukadevi 9486644542

CUSTOMERS LIST IN ALPHABETICAL ORDER

anandamurugan 9486153102
Renukadevi 9486644542
c coding problems

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes