Tuesday 11 December 2012

Implement Strcspn

/*
* This program will check the first unmatched characters of
* target string 'tar' to the source string 'src'
* and returns the total number of first unmatched characters.
* */
int mystrcspn(char *src, char *tar)
{
char *t; /*For retaing the address of tar string*/
int count = 0; /*For counting */
for(;*src != '\0'; src++) {

for(t = tar; *t != '\0'; t++) {
if( *src == *t )
return (count);
}
if(*t == '\0')
count++;
}
return (count);
}

No comments:

Post a Comment