Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-05-2015, 12:39 PM
|
#1
|
LQ Newbie
Registered: Apr 2015
Posts: 3
Rep:
|
Write a program about string! C program(in C++) Help!!!!!!!!!!!!!!
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!
|
|
|
04-05-2015, 12:51 PM
|
#2
|
Moderator
Registered: Aug 2002
Posts: 26,285
|
Welcome to LinuxQuestions.
Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.
|
|
2 members found this post helpful.
|
04-06-2015, 09:41 AM
|
#3
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,900
|
So what did you wait until Sunday before the assignment is due to post this? (And posted in multiple forums...) You didn't even start the assignment earlier?
As said, we're not here to do your homework, see LQ Rules. Try it yourself, post what you have and perhaps some will offer suggestions how to improve your answer.
|
|
|
All times are GMT -5. The time now is 10:37 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|