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);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.