Structures and Pointers – Strings – Problem #3
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
1. Write the following text editor program in C. For this, you need to write the following functions. For simplicity, assume that all inputs to the program 1s in lower case characters only. a) main: Define a global array of 100 string pointers and name it as sptr. In an infinite loop, display a menu and prompt the user to enter a choice(l-6). Based on the user choice (1--6), call the appropriate function (1->create(), 2->lengthStat(),., 6->searchReplace()) described in the following. Terminate, when the user enters '0. b) create: Prompt the user how many words (n< 100) to enter. Read n words of various lengths (each less that 30chars) from the keyboard one at a time, dynamically allocate just enough memory for each word entered, and store it so that the next element of sptr points to it [Note that each element of sptr is a string pointer]. The entered words therefore get sequentially placed in sptr. Display all the words that have been entered by the user. c)lengthStat: Display the number of words that are of lengths: between 1--2 letters, between 3 - 5 letters, and larger than 5 letters. d) letterstat: Find and display the number of occurrences of the vowels ('a to "u) by considering all the words together. e)search: Read a word from the user and check if the word is present in sptr. If present, display the sequence number in sptr at which it 1s present. If it is present multiple times, display each occurrence and the sequence number in sptr at which the word is present. f)removeDuplicate: Find all duplicate words, deallocate the duplicates, and display the updated list of words. g) searchReplace: Read a word from the user and check if the word is present in sptr. If so, prompt the user to enter the new word for replacement. Replace (deallocate old word and allocate the new word) the word with the new word. If a word being searched is present at multiple locations, replace only the first occurence. Display the updated list of words Total-30 Marks|