/* strings5_strcspn.c */ #include #include int main() { char str1[] = "Hello, World"; char str2[] = ","; /* string I want to search for */ char* result = strstr( str1, str2 ); size_t index = strcspn( str1, str2 ); if( result == NULL ) printf( "Could not find '%s' in '%s'\n", str2, str1 ); else { printf( "Found a substring matching first occurrence of ',': '%s'\n", result ); printf( "Index for match in original string is str[%d]\n", index); printf( "Index for match in substring is result[%d]\n", strcspn(result, str2)); } return 0; }