2) Write the definition of a recursive function named find that is passed a c-string and a char and returns with the pos of the char if it finds the char within thec-string or returns -1 if the char is not found. You must implement the expected function, but you may write other code as long as your additional code helps find perform as expected. For example, if a cstring named cstr contains the value "this is my string" and a char named c containing the value 'i' is passed in to find, the function should return the value 2. However, if c contained the value 'a', then find would return -1. This is what the function call for the example above would look like: int foundat = find(cstr, c); NOTE: This function takes a c-string, NOT a string. No c-string functions may be invoked.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
icon
Related questions
Question

C++

2) Write the definition of a recursive function named find that is passed a c-string and a char and returns with the pos of the
char if it finds the char within the c-string or returns -1 if the char is not found. You must implement the expected function, but
you may write other code as long as your additional code helps find perform as expected.
For example, if a c-string named cstr contains the value "this is my string" and a char named c containing the value 'i'
is passed in to find, the function should return the value 2. However, if c contained the value 'a', then find would return -1.
This is what the function call for the example above would look like:
int foundat = find(cstr, c);
NOTE: This function takes a c-string, NOT a string. No c-string functions may be invoked.
Transcribed Image Text:2) Write the definition of a recursive function named find that is passed a c-string and a char and returns with the pos of the char if it finds the char within the c-string or returns -1 if the char is not found. You must implement the expected function, but you may write other code as long as your additional code helps find perform as expected. For example, if a c-string named cstr contains the value "this is my string" and a char named c containing the value 'i' is passed in to find, the function should return the value 2. However, if c contained the value 'a', then find would return -1. This is what the function call for the example above would look like: int foundat = find(cstr, c); NOTE: This function takes a c-string, NOT a string. No c-string functions may be invoked.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning