Search On Codescracker Search: F T G L y
Search On Codescracker Search: F T G L y
f t g l y
Home
Java
C
C++
HTML
CSS
JavaScript
SQL
PHP
Perl
Python
C#
Objective-C
Tips
C Programming Examples
C Programming Examples
Print Hello World
Take Input from User
Print Integer
Add two Numbers
Check Even or Odd
Check Prime or Not
Check Alphabet or Not
Check Vowel or Not
Check Leap Year or Not
Check Reverse equal Original
Add Subtract Multiply Divide
Make Calculator
Add Digits of Number
Calculate Average Percentage Marks
Calculate Arithmetic Mean
Calculate Student Grade
Print Table of Number
Print Prime Numbers
Add n Numbers
Interchange Numbers
Reverse Numbers
Swap two Numbers
Count Positive Negative Zero
Find Largest of two Numbers
Find Largest of three Numbers
Find Factorial of Number
Find HCF LCM
Calculate Area Perimeter
Calculate Area Circumference
Fahrenheit to Centigrade Conversion
Centigrade to Fahrenheit Conversion
Print ASCII Values
Print Fibonacci Series
Check Palindrome or Not
Check Armstrong or Not
Generate Armstrong Numbers
https://codescracker.com/c/program/c-program-sort-string.htm 02-05-17
C Program to Sort Strings in Alphabetical Order Page 2 of 6
https://codescracker.com/c/program/c-program-sort-string.htm 02-05-17
C Program to Sort Strings in Alphabetical Order Page 3 of 6
Sort Strings in C
To sort strings in alphabetical order in C programming, you have to ask to the user to enter some set of strings (5
strings here). Now start comparing one strings with other and sort all the strings in alphabetical order then display
all the strings in alphabetical order as shown here in the following program.
Following C program ask to the user to enter five strings like names to sort them in alphabetical order then display
the sorted strings in alphabetical order on the screen:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str[5][20], t[20];
int i, j;
printf("Enter any five string (name) : ");
for(i=0; i<5; i++)
{
scanf("%s",str[i]);
}
for(i=1; i<5; i++)
{
for(j=1; j<5; j++)
{
if(strcmp(str[j-1], str[j])>0)
{
strcpy(t, str[j-1]);
strcpy(str[j-1], str[j]);
strcpy(str[j], t);
}
}
}
printf("Strings (Names) in alphabetical order : \n");
for(i=0; i<5; i++)
{
printf("%s\n",str[i]);
}
getch();
}
When the above c program is compile and executed, it will produce the following result:
https://codescracker.com/c/program/c-program-sort-string.htm 02-05-17
C Program to Sort Strings in Alphabetical Order Page 4 of 6
C Online Test
https://codescracker.com/c/program/c-program-sort-string.htm 02-05-17
C Program to Sort Strings in Alphabetical Order Page 5 of 6
Tools
Calculator
Quick Links
Signup - Login - Give Online Test
C++ Program
to Sort...
C++ Program
to Print...
C Program to
Print...
C Program to
Check...
C Program to
Check...
C Program to
Convert...
Python
Program to...
C Program to
Print Date
C Program
Linear Search
C Program to
Insert...
C++ File
Handling
C++ Program
Selection Sort
C++
Functions
https://codescracker.com/c/program/c-program-sort-string.htm 02-05-17
C Program to Sort Strings in Alphabetical Order Page 6 of 6
codescracker.com
https://codescracker.com/c/program/c-program-sort-string.htm 02-05-17