返回值 | 含义 |
<0 | 第一个不匹配的字符在ptr1中的值比在ptr2中的值低 |
0 | 两个字符串的内容相等 |
>0 | 第一个不匹配的字符在ptr1中的值大于ptr2中的值 |
/* 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; } |
strcmp | 比较两个字符串(function ) |
memcmp | 比较两个内存块(function ) |
strrchr | 查找字符串中最后出现的字符(function ) |
strspn | 获取字符串中字符集的范围(function ) |