Structures and Pointers – Strings – Problem #7

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

Difficulty: medium

Problem Statement

Write a function void dict_first(char s[], int n, char * first), which given an array s of n (< 10) strings (each of length < 20), finds the first string in the array if the strings were arranged according to dictionary order. In the above function, use the strcmp function in the strings.h library to compare dictionary order between two strings. Write a main function which reads an integer n. Then reads n strings consisting of lower case alphabets only, calls the above function, and prints the first string according to dictionary order. Example, if n = 4, and the input strings are “hello”, “world”, “happy”, “diwali”, output string should be “diwali”.

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

Lab Problem Statement

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

Interactive C Compiler · Problem #7

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.