LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 04-05-2015, 12:39 PM   #1
Zoe Zhang
LQ Newbie
 
Registered: Apr 2015
Posts: 3

Rep: Reputation: Disabled
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!
 
Old 04-05-2015, 12:51 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,285

Rep: Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137
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.
Old 04-06-2015, 09:41 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,900
Blog Entries: 13

Rep: Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947
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.
 
  


Reply


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
C program(use C++) write a program about string Zoe Zhang Linux - Software 1 04-05-2015 12:40 PM
[SOLVED] C++ how to get a string parameter from another program with '|' or < in bash embeddedPROJECTS Linux - General 2 11-10-2013 05:44 PM
Execute command upon every string that gets outputed from a program Tomás Ó hÉilidhe Linux - General 7 12-05-2008 05:04 AM
string concatenation in c/c++ for a socket program mohtasham1983 Programming 3 02-14-2007 06:42 PM
Exercise 1-9. Write a program to copy its input to its output, replacing each string zombi3 Programming 3 12-21-2003 03:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:37 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