C program(use C++) write a program about string
Write a C program that input, print, find and replace text.
• Input: The program prompts the user to enter a line of text of at most 80 characters (may include space in-between) • Print: The program prints out the line of characters • Find: The program prompts the user to enter a word-to-find (not including space) of at most 20 characters. The program finds if the word appears in the line of text. If the word is found, then it proceeds to the replace function immediately. • Replace: The program prompts the user to enter a word-for-replace (not including space) of at most 20 characters. The program replaces the first appearance of the word-to-find with the word-for-replace. No error checking is required. Useful tips: • Consider the string str char str[] = "Good luck!"; *str is the character ‘G’ *(str+1) is the character ‘o’ Consider another string str2 char *str2 = (str+5); str2 can be considered as the string “luck!” Example: (Information entered by users is underlined) 1> Enter the text 2> Print the text 3> Find text and replace 0> Exit Your choice? 1 Please enter the text (at most 80 characters): I am a boy. 1> Enter the text 2> Print the text 3> Find text and replace 0> Exit Your choice? 2 The text is: I am a boy. 1> Enter the text 2> Print the text 3> Find text and replace 0> Exit Your choice? 3 Text to find (at most 20 characters): man "man" not found! 1> Enter the text 2> Print the text 3> Find text and replace 0> Exit Your choice? 3 Text to find (at most 20 characters): boy "boy" is found! Replace by (at most 20 characters): girl Text replaced successfully! 1> Enter the text 2> Print the text 3> Find text and replace 0> Exit Your choice? 2 The text is: I am a girl. 1> Enter the text 2> Print the text 3> Find text and replace 0> Exit Your choice? 0 Thank you! |
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
Continue here: http://www.linuxquestions.org/questi...lp-4175538821/ |
All times are GMT -5. The time now is 07:51 AM. |