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?
9 Answers
+ 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?
+ 3
It happens :)
+ 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.
+ 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.
+ 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?
+ 1
@Martin thank you. Seems like I need to be more careful while typing.
0
oh ho sorry I counted wrong...so disappointing.Thank you @Mark
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?
0
@Martin I am working from the book ..I have written the code following the given solution in the book