Home > Back-end >  O bosses how to write this
O bosses how to write this

Time:11-28

A string STR. Any input, find a substring str1 appeared for the first time the location of the pos, if not the substring pos=1, for example: STR []="abaababbaabaabba str1 []=" abb ", pos=5 if str1 []="aaa" pos=1

CodePudding user response:

 int find_substr_first_pos (const char * STR, const char * substr) 
{
Const char * PSTR=STR;
Int I=0, pos=1;

While (PSTR [I]) {
If (STRNCMP (PSTR + I, substr, strlen substr ())==0) {
Pos=I;
break;
}
}

Return pos.
}

For your reference ~

No test, it is recommended that the landlord to call it and test it

CodePudding user response:

Thank you but I am a beginner, these seem to be haven't learned
  • Related