Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

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 solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes