Home > Back-end >  C problem solving
C problem solving

Time:12-02

A custom function bool fun (char * s, int start, int len, char * & amp; Subs), the function of the function: by a substring in a string s have it known subs, substring from the start of s (subscript), length of len, take a substring operation is successful, the function returns true, otherwise it returns false, and design the corresponding test program, string manipulation library function shall be used for ()



To solve the ~

CodePudding user response:

One copy to a character subs

CodePudding user response:

Bool fun (char * s, int start, int len, char * & amp; Subs)
{
If (s==NULL)
return false;

Char * STR=s;
Int nCount=0;
While (* str++!=NULL)
+ + nCount;

If (start + len & gt; NCount)
return false;

If (subs==NULL)
{
Subs=s + start;
}
The else
{
STR=s + start;
for (int i=0; i {
Subs [I]=STR [I];
}

Subs [len]=0;
}

return true;
}

Int main ()
{
Char sub [100].
Char * psub=sub;
Fun (" this is the test string!" , 3, 5, psub);

system("pause");

return 0;
}
  • Related