LPU CSE101 C Programming Sorting of strings To sort the strings in increasing

Lpu cse101 c programming sorting of strings to sort

This preview shows page 17 - 20 out of 20 pages.

©LPU CSE101 C Programming Sorting of strings To sort the strings in increasing order. That is if list of names is given then sort the list in alphabetical order. Use strcmp() and strcpy() functions.
Image of page 17
©LPU CSE101 C Programming #include<stdio.h> #include<conio.h> #include<string.h> main() { char name[20][20]; char temp[20]; int i,j,n,l; printf("Enter the no. of string to be sorted"); scanf("%d",&n); printf(“Enter %d strings:\n", n); for(i=0;i<=n;i++) gets(name[i]); for(i=0;i<=n;i++) { for(j=i+1;j<=n;j++) { l = strcmp(name[i], name[j]); if(l>0) // if first string is greater then swap { strcpy(temp, name[i]); strcpy(name[i],name[j]); strcpy(name[j],temp); } } } puts("Sorted list is:\n"); for(i=0;i<=n;i++) puts(name[i]); getch(); } Program to sort the strings using arrays.
Image of page 18
©LPU CSE101 C Programming Enter the no. of string to be sorted 3 Enter 3 strings lovely aananya aman preet Sorted list is: aananya aman preet lovely
Image of page 19
©LPU CSE101 C Programming [email protected] Next Lecture Marking the attendance of students by passing attendance sheet …?? Pointer
Image of page 20

You've reached the end of your free preview.

Want to read all 20 pages?

  • Spring '18
  • Aman
  • ASCII, string conversion functions

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors