int strcmp (const char *str1, const char *str2);

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.

str1 C string to be compared.
str2 C string to be compared.
num Maximum number of characters to compare.



strcmp(string1,string2)比較兩個string,

strncmp(string1,string2,n)則只比較前n個字元

若是string1 若是string1=string2則傳回值=0,
若是string1>string2則傳回值>0,

BB 發表在 痞客邦 PIXNET 留言(0) 人氣()