How to Find Substrings in C++: A Step-by-Step Guide

In summary, the conversation discusses the topic of finding a substring within a string in a C++ programming class. The individual is struggling to find an answer in their textbook and is seeking help from others in the class. They describe the problem and provide an example of the expected output.
  • #1
crimsondancer
1
0
I was reading my textbook to study for a test in my C++ class and I cam across this question and the answer is not in the book. I'm afraid I might need to know how to do something like this for my test and there isn't an example of one like it in my book. I'm not sure how to do it so I don't have any code to show you guys. I was wondering if anyone knew the answer to this question. Thanks!

Here it is:

Substring function

Write a program that finds a substring inside a string. Main program asks users to type a string and then a substring. Then, program calls a subfunction int mystrstr(char *str, char *substr). Inside the mystrstr subroutine, program searches substring substr in the string str and returns the starting position of the substring in the string. If the substring is not located in the string, then subroutine return -1. After searching the position, main program prints out the string from the position to the end of string of the string. e.g. string: "C++ program is really fun", substring: "program", Then, your program will print "program is really fun"
 
Technology news on Phys.org
  • #2
What have you tried?
 

What is a "Program from C++ text book"?

A "Program from C++ text book" refers to a computer program written in the C++ programming language that is typically used as a learning tool in a textbook or educational setting.

What is the purpose of a "Program from C++ text book"?

The purpose of a "Program from C++ text book" is to provide a practical example of how to use the C++ programming language to solve a specific problem or complete a task.

Do I need to have prior programming experience to understand a "Program from C++ text book"?

No, most "Programs from C++ text books" are designed for beginners and assume little to no prior programming experience. However, some knowledge of basic programming concepts may be helpful.

Can I modify a "Program from C++ text book" for my own use?

Yes, you are free to modify and adapt a "Program from C++ text book" for your own use. However, it is important to understand the code and its purpose before making any changes.

Where can I find "Programs from C++ text books"?

"Programs from C++ text books" can be found in C++ textbooks, online resources, and educational websites. They may also be provided as supplemental materials in a classroom setting.

Similar threads

  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
3
Views
859
  • Programming and Computer Science
2
Replies
40
Views
2K
  • Programming and Computer Science
3
Replies
73
Views
4K
  • Programming and Computer Science
3
Replies
89
Views
4K
  • Programming and Computer Science
4
Replies
118
Views
6K
  • Programming and Computer Science
Replies
19
Views
909
  • Programming and Computer Science
Replies
34
Views
2K
  • Programming and Computer Science
Replies
4
Views
3K
Back
Top