Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++; Header file // ------------------------------------------------------------

ID: 3797160 • Letter: C

Question

C++; Header file

// ------------------------------------------------------------- //

// Set resultString[] to a string value that is a copy of a specified substring of original string s.
// If specified start position is not located within the string s, then set resultString to the empty string ("").
// If specified len < 0, or if (start + len) > the length of s, then set resultString to the longest possible substring.

void stringSubstring(
        char resultString[ ], // new string buffer
const int resultBuffSize, // result array buffer size
const char s[ ], // the original string
const int start, // starting position of substring within s
const int len) // length of substring within s

Explanation / Answer

Hopefully this will work.

void stringSubstring(
char resultString[], // new string buffer
const int resultBuffSize, // result array buffer size
const char s[], // the original string
const int start, // starting position of substring within s
const int len) // length of substring within s
// len<0: longest possible substring
{

int slen = stringLength(s[]); // length of String s
int total = start + len;

if(start > slen){
resultString[] = "";
}
else{
if((len < 0) || (total > slen)){

resultString[] = substring(s[],start,slen);
}
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote