C program to arrange the given names in alphabetical order using pointers


Posted Date:     Total Responses: 0    Posted By: Sunil Reddy   Member Level: Gold   Points/Cash: 1   


#include

#define COUNT 5
main()
{
char *names[5], temp[20];
int m, n;
for (m = 0; m < COUNT; m++)
{
printf(“\nEnter name[%d] : “,m);
names[m] = (char *) malloc (20);
scanf(“%s”,names[m]);
}
for (m = 1; m <= COUNT; m++)
for (n = 1; n <= COUNT - m; n++)
if (strcmp(names[n - 1], names[n]) > 0)
{
strcpy(temp, names[n - 1]);
strcpy(names[n - 1], names[n]);
strcpy(names[n], temp);
temp[0] = ‘\0’;
}
printf(“\nSorted list is “);
for (m = 0; m < COUNT; m++)
printf(“\n%s”, names[m]);
}


Project Feedbacks


No feedbacks found. Be the first to respond...

Post Feedback
You must Sign In to post a feedback.
Next Project: C program to find the factorial of a given number using pointers.
Previous Project: Time Query

Return to Project Index

Post New Project


Related Projects

Awards & Gifts
Active Members
TodayLast 7 Daysmore...

ISC Technologies, Kochi - India. Copyright © All Rights Reserved.