0

string strspn() function

https://code.sololearn.com/ca24a5A8a224 8.16 Write and test the strspn() function. I am trying to get 4 as output when I entered debug as string1 and debugger as string2..but here it is returning 5..what am I doing wrong here?

29th Apr 2021, 9:39 AM
Ramisa Fariha
Ramisa Fariha - avatar
9 odpowiedzi
+ 4
Hi Ramisa Fariha It is correct, you should get 5 as answer. The string1 "debug" has 5 letters and is a substring of string2 "debugger". Why you say you should get 4?
29th Apr 2021, 12:15 PM
Mark
+ 3
It happens :)
29th Apr 2021, 12:54 PM
Mark
+ 3
Hi Martin Taylor You are right. You answer is more complete. Also, I did not mean to imply that string2 should be a substring of string1 in the function strspn(). It just happen to be the case for the two input strings she gave. I was merely pointing out that she miscounted the number of letters.
29th Apr 2021, 1:28 PM
Mark
+ 3
No need to apologise Martin Taylor. I misunderstood things myself. I just now figured out what Ramisa Fariha is trying to accomplish. I needed your examples to understand the explanation on hers code comments. I read them too superficially.
29th Apr 2021, 2:14 PM
Mark
+ 1
Hi Ramisa Fariha Because you are returning the size of string1, as you pointed out in line 26: return ( p1 - s1 ) ; // returning length of s1 Fariha, between what you explain in your code comments and what Martin Taylor shows as example, which one means what function strspn should do? What exactly do you want to count?
29th Apr 2021, 1:52 PM
Mark
+ 1
@Martin thank you. Seems like I need to be more careful while typing.
29th Apr 2021, 4:17 PM
Ramisa Fariha
Ramisa Fariha - avatar
0
oh ho sorry I counted wrong...so disappointing.Thank you @Mark
29th Apr 2021, 12:53 PM
Ramisa Fariha
Ramisa Fariha - avatar
0
@Martin I tried using the second one as input i.e beautiful and guidebook it returns 9 instead of 2 ..what am I doing wrong?
29th Apr 2021, 1:45 PM
Ramisa Fariha
Ramisa Fariha - avatar
0
@Martin I am working from the book ..I have written the code following the given solution in the book
29th Apr 2021, 2:17 PM
Ramisa Fariha
Ramisa Fariha - avatar