Reputation: 145
char * strpbrk (char * str1, const char * str2 );
Returns a pointer to the first occurrence in str1 of any of the characters that are part of str2, or a null pointer if there are no matches.
int strcspn( const char * str1, const char * str2 );
The length of the initial part of str1 not containing any of the characters that are part of str2.
seems both work same , is there any major differences?
Upvotes: 5
Views: 2416
Reputation:
These functions are hardly having any application in C++ programming. Well I think so. But still if you want to know about it here is the answer,
In your question strcspn
returns a character position whereas strpbrk
returns a pointer.
Also by chance if no character is found, strpbrk
returns a null pointer; IIRC, under the same circumstances strcspn
returns the index of the NUL at the end of the string.
Also I had got a descent explanation about strcspn() and strpbrk(). Check the link.
Upvotes: 5