LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Closed Thread
  Search this Thread
Old 04-05-2015, 10:38 AM   #1
Zoe Zhang
LQ Newbie
 
Registered: Apr 2015
Posts: 3

Rep: Reputation: Disabled
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!
 
Old 04-05-2015, 11:40 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,199

Rep: Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089
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/
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] C++ how to get a string parameter from another program with '|' or < in bash embeddedPROJECTS Linux - General 2 11-10-2013 04:44 PM
script for executing a program and doing string comparison b-neva Programming 9 05-07-2009 03:52 PM
Execute command upon every string that gets outputed from a program Tomás Ó hÉilidhe Linux - General 7 12-05-2008 04:04 AM
string concatenation in c/c++ for a socket program mohtasham1983 Programming 3 02-14-2007 05:42 PM
Exercise 1-9. Write a program to copy its input to its output, replacing each string zombi3 Programming 3 12-21-2003 02:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration