Table of Contents

strspn

#include <stdlib.h>
size_t strspn(const char *str1, const char *str2);

strspn C Sourcecode Example

/* 
 * strspn example code
 * http://code-reference.com/c/string.h/strspn
 */
#include <stdio.h>
#include <string.h>
 
int main( void )
{
    const char string[] = "the answer is 42";
    int pos = strspn(string, "the answer = 42");
    printf("different char at position :%d\n",pos+1);
    return 0;
}

output of strspn c example

  different char at position :12