Structures and Pointers – Strings – Problem #4
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
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:~$