Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- struct person
- {
- char name[10];
- int rno;
- };
- typedef struct person NAME;
- NAME stud[10], temp[10];
- void main()
- {
- int no,i;
- void sort(int N);
- fflush(stdin);
- printf("Enter the number of students in the list\n");
- scanf("%d",&no);
- for(i = 0; i < no; i++)
- {
- printf("\nEnter the name of person %d : ", i+1);
- fflush(stdin);
- gets(stud[i].name);
- }
- for(i=0;i<no;i++)
- {
- printf("%-10s\n",temp[i].name,temp[i].rno);
- }
- sort(no); /* Function call */
- printf("\n*****************************\n");
- printf (" Names after sorting \n");
- printf("\n*****************************\n");
- for(i=0;i<no;i++)
- {
- printf("%-10s\n",stud[i].name,stud[i].rno);
- }
- printf("\n*****************************\n");
- }
- void sort(int N)
- {
- int i,j;
- NAME temp;
- for(i = 0; i < N-1;i++)
- {
- for(j = i+1; j < N; j++)
- {
- if(strcmp(stud[i].name,stud[j].name) > 0 )
- {
- temp = stud[i];
- stud[i] = stud[j];
- stud[j] = temp;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement