Structures and Pointers – Strings – Problem #1
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
In this program you will sort a list of student records. Declare a global structure named student in main() that can store the roll number and the name of a student. Assume that the name consists of at most 99 English letters, and the roll number is a combination of 9 digits and English letters as we see in IITKGP. Ask the user for the number of students. Then dynamically allocate an array of structure student of appropriate size. Populate it with user input. Use scanf(“%[^\n]s”...) for scanning the name. Ask the user to enter to sort the array by roll number, and to sort the array by name. Use bubble sort to sort the array. The order should be the lexicographic order of the respective string. To swap two structure variables in the list, you must use a function with the following prototype: void swap(struct student *A, struct student *B); Print the sorted student records as shown in the examples below.