+ 1
🤔Can anyone tell me why work 2,3,4 are getting impacted by work1.
Separately they are working well but together value of work 1 is overriding the work 2,3,4. Please help😞 https://code.sololearn.com/czoEZvByJcFh/?ref=app
5 Answers
+ 1
don't use static for k and
while( p[j] ){ valid but after that
if ( p[ ++j ] .. May out of bounds.. so Reverse it
while ( p[++j ] ){
if( p[j] == str[ ++i] )
+ 2
I didn't test this, but I think j should get reset to 0 in the beginning of the for loop in strCompare.
+ 1
what do mean by overriding here..?
What is your expected output? can you add clear details??
0
Jayakrishna🇮🇳 It's working thanks can u explain what was the problem there. Please
0
static variable only once initialized and retain its value between function call throughout program.
And as already said,
Ex: p=>"ABC", str => "zzABC", if p[ j ] = 'C' then
if( p[ ++j ] == str[ ++i ] ) here j is out of bounds and beyond p length so value returned is \0 . If condition is false, else part reset k=0;
But corrected code while( p[ ++j ] ) stops loop further... So k=1 at end.
Hope it clears...