- #1
James889
- 192
- 1
Hi,
im trying to write my own version of the C standard function strspn.
It returns the number of characters in str2 that exists in str1.
I cannot get mine to work.
if i try it with something like strspn("1214bk","1214"), it returns 16386...
:(
im trying to write my own version of the C standard function strspn.
It returns the number of characters in str2 that exists in str1.
I cannot get mine to work.
Code:
#include <stdio.h>
#include <stdlib.h>
int strspn(const char *str1, const char *str2){
int n;
const char *s,*k;
s = str1;
k = str2;
while(*s++ != '\0'){
for(; *k++ != '\0';){
if(*s == *k)
n++;
}
}
return n;
}
if i try it with something like strspn("1214bk","1214"), it returns 16386...
:(