Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define a function named isSubstring that takes two C-strings s1 and s2 and returns true if s1 is a substring of s2; returns false otherwise.

Define a function named isSubstring that takes two C-strings s1 and s2 and returns true if s1 is a substring of s2; returns false otherwise. For example,

"abc" is a substring of "aaabc";

"you" is a substring of "how are you?";

"" (empty string) is a substring of any C-string;

"aaab" is a substring of "123aaaabcd";

"ab" is not a substring of "aacb";

"aaa" is not a substring of "aa";

just testing one case in the example, but the function is correct for all cases.

Do not use the substring function in the library to solve this problem as I have not learned.

Thank you so much.

This is my function code:

bool isSubstring(char array1[], char array2[]) { bool isSub = false; int length1 = 0; int length2 = 0; while (array1[length1] != '\0') length1++; while (array2[length2] != '\0') length2++; for (int i = 0; i <= length1 - length2; i++) { int j = 0; if (array2[j] == array1[i]) { for (; j < length2; j++) if (array2[j+1] == array1[i+1]) isSub = true; if (j == length2) return isSub; isSub = false; } } return isSub; }

I do not know what I am wrong. Can you help me to edit.

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

Step: 3

blur-text-image

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions