Structures and Pointers – Strings – Problem #4

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

Difficulty: medium

Problem Statement

Take 10 names, which include the first name and the surname, as input from the user. Assume that any first name and any surname contains at most 50 characters. Sort these 10 names in dictionary according to their first names and output. Also sort these 10 names in dictionary order according to their surnames and output. You are not allowed to copy one string into another either by using strcpy function or by writing a loop to copy character-by-character or by any other means. Hint: Use pointers. Submit one (single) C/C++ program. Sample Output palash@palash-ThinkPad-X1-Yoga-3rd:~$ ./a.out Write 10 names Ram Das Sham Mondal Sachin Tendulkar Lata Mangeskar Sourav Ganguly Sunil Gavaskar Ritwik Roshan Satyajit Ray Rabindranath Tagore Prakash Deb Sorted according to first name: Lata Mangeskar Prakash Deb Rabindranath Tagore Ram Das Ritwik Roshan Sachin Tendulkar Satyajit Ray Sham Mondal Sourav Ganguly Sunil Gavaskar Sorted according to last name: Ram Das Prakash Deb Sourav Ganguly Sunil Gavaskar Lata Mangeskar Sham Mondal Satyajit Ray Ritwik Roshan Rabindranath Tagore palash@palash-ThinkPad-X1-Yoga-3rd:~$

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

Lab Problem Statement

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

Interactive C Compiler · Problem #4

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.