Tuesday 11 December 2012

Implement strspn

*
* This program will Count the first matched character
* from target string "tar" to the source string "src"
* and returns the value of count.
* */
int mystrspn(const char *src, const char *tar)
{
const char *t = NULL;/*For retaing the address of target string*/
int count = 0; /*For counting*/
for(;*src != '\0'; src++){
for(t = tar; *t != '\0'; t++)
if(*src == *t){
count++;
break;
}
if(*t == '\0')
return(count);
}
return(count);
}

No comments:

Post a Comment