Computer Programming C Laboratory: String C Programs

Write a C program to arrange names in Alphabetical order

Sample programs on Strings - C Programming

Write a C program to arrange names in Alphabetical order

Arranging names in alphabetical order is nothing but the string sorting means that the names are arranged in either ascending or descending order by comparing each of the name.

Here, first of all, we have to capture the names into an array up to the keyword END encounters from the keyboard. Then we can compare the first string with subsequent strings using selection sort method if it gives greater than zero comparison result then move them to appropriate place using another variable until all strings are compared.

#include <stdio.h>

#include <conio.h>

main()

{

char names[20][20], temp[10], c;

int i,j,k,n=0;

printf("Enter Names to stop type keyword END ………..\n");

scanf("%s", names[n]);

while(strcmp(names[n], "END") > 0)

{

         n++;

         scanf("%s", names[n]);

}

printf("\n");

for(i=0;i<n;i++)

printf("%10s", names[i]);

printf("\n");

printf("\n");

printf("Number of Names....................  %d\n", n);

for(i=0;i<n‒1;i++)

{

     for(j=i+1;j<n;j++)

    {

        if (strcmp(names[i], names[j])>0)

        {

            strcpy(temp, names[i]);

            strcpy (names[i], names[j]);

            strcpy(names[j], temp);

        }

    }

printf("After Sorting the Names are.....\n");

for(i=0;i<n;i++)

printf("%10s", names[i]);

printf("\n");

}

OUTPUT

Enter Names to stop type keyword END……..

 suji lak muni anil durga anil chiru babu END

suji lak muni anil durga anil chiru babu

Number of Names ………. 8

After Sorting the Names are …..

anil anil babu chiru durga lak muni suji

 

Computer Programming C Laboratory: String C Programs : Tag: C Programming : - Write a C program to arrange names in Alphabetical order


Computer Programming C Laboratory: String C Programs



Under Subject


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation



Related Subjects


English Essentials I

EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


தமிழர் மரபு - Heritage of Tamils

UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Calculus

MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I

PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Chemistry I

CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Makerspace

ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming Python

CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Fundamentals of Electrical and Electronics Engineering

EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Mechanical Engineering

ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Civil Engineering

CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing

CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I Laboratory

PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Applied Chemistry I Laboratory

CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming Python Laboratory

CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electronics and Electrical Engineering

EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing - Laboratory

CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation