int strncmp ( const char * str1, const char * str2, size_t num );
<0
0
>0
12345678910111213141516
/* strncmp example */ #include <stdio.h> #include <string.h> int main () { char str[][5] = { "R2D2" , "C3PO" , "R2A6" }; int n; puts ("Looking for R2 astromech droids..."); for (n=0 ; n<3 ; n++) if (strncmp (str[n],"R2xx",2) == 0) { printf ("found %s\n",str[n]); } return 0; }
Looking for R2 astromech droids... found R2D2 found R2A6