Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Explain the steps in the following code: Can someone explain what the following code is doing step by step or why these steps are being

Explain the steps in the following code:

Can someone explain what the following code is doing step by step or why these steps are being taken? We just got introduced to C-String so I'm a little confused. Thanks.

#include // Add additional headers here using namespace std;

string STUDENT = "hsohn2"; // Add your name Blackboard/occ-email ID

#include "h21.h"

const char * findStr (const char *str1, const char *str2) { if (*str2 == '\0') return str1; const char * result = nullptr; const char * beg = str1; while(*beg ) { const char * p1 = str2; const char * p2 = beg; bool found = true; while(*p1 && *p2 ) { if(*p1 != *p2) { found = false; break; } p1++; p2++; } if(found ) return beg; beg++; } return result; }

This is what the function is supposed to do:

/** * Finds the first occurrence of str2 which appears in str1. * Returns a pointer to the first occurrence of str2 in str1. * If no match is found, then a null pointer is returned. * If str2 points to a string of zero length, then the argument str1 is returned. * * @param str1 C-string to search through. * @param str2 C-string to search for. * @return */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

Question Can a self-employed person adopt a money purchase plan?

Answered: 1 week ago