Compares the first n characters of two strings #include <string.h> int strncmp ( const char *s1 , const char *s2 , size_t n ); The strncmp( ) function compares at most the first n characters in the two strings addressed by its pointer arguments. Characters that follow a null character are ignored. strncmp( ) returns a value indicating the result as follows:
Examplechar *weekdays[ ] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; char date[ ] = "Thu, 10 Mar 2005 13:44:18 +0100"; int dow; for ( dow = 0; dow < 7; dow++ ) if ( strncmp( date, weekdays[dow], 3 ) == 0 ) break; See Alsostrcmp( ), wcsncmp( ), wcscmp( ) |