December 2005
Beginner to intermediate
618 pages
20h 19m
English
strncmp
Compares the first n characters of two strings
#include <string.h> intstrncmp( const char *s1, const char *s2, size_tn);
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:
The two strings, or arrays of
n characters, are equal.
The string or array of n
characters addressed by s1 is
greater than that addressed by
s2.
The string or array of n
characters addressed by s1 is less
than that addressed by s2.
char *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;Read now
Unlock full access