int strncmp ( const char * str1, const char * str2, size_t num );

Compares up to num characters of the C string str1 to those of the C string str2.

This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ, until a terminating null-character is reached, or until num characters match in both strings, whichever happens first.

*如果到达 terminating null-character也会停止对比的。



程序:

      1 #include <stdio.h>
      2
      3 int main(void){
      4     int c;
      5     char *a;
      6     a = "aaaaaac";
      7     char b[20] = "aaaaaabc";
      8     printf("%s\n",a);
      9     printf("%s\n",b);
     10
     11     printf("%d\n",sizeof(b));
     12     printf("*a:%d\n",sizeof(*a));
     13     printf("a:%d\n",sizeof(a));
     14     c =strncmp(a,b,sizeof(b));
     15     printf("%d\n",c);
     16
     17     return 0;
     18 }



结果:

aaaaaac
aaaaaabc
20
*a:1
a:4
1

你可能感兴趣的:(c,function,UP,character,each)