Structures and Pointers – Strings – Problem #1

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: medium

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.

Back to Lab Problems
Structures and Pointers/Strings/Problem #1

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #1

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.