Such as the main series of abcaabc
Substring ABC then return 1 5
Which bosses can, c + + white
CodePudding user response:
Using STRSTR functionOne example of C:
# include & lt; stdio.h>
# include & lt; String. H>
Void foundPos (char * dest, const char * subs, char * buf)
{
Char * PCH.
Int pos.
Char tmpStr [10].
PCH=STRSTR (dest, subs);
While (PCH!=NULL) {
Pos=PCH - dest;
Sprintf (tmpStr, "% d", pos + 1);
Strcat (buf, tmpStr);
Strcat (buf, "");
PCH=STRSTR (PCH + 1, subs);
}
}
Int main ()
{
Char STR []="abcbbbabc";
PCH char [100]={0};
Printf (" & the for 'ABC' in the \ "% s \ " n ", STR);
FoundPos (STR, "ABC", PCH);
Printf (" % s \ r \ n ", PCH);
return 0;
}