c語言strcmp的用法
本文已影響
2.5W人
函數 int stringcompare(char *source, char *target) 比較字符串 source 和 target,並根據 source 是否小於、等於或大於 target 的結果分別返回負整數、0或者整數。該返回值是 source 和 target 由前後逐字符比較時遇到的第一個不相等字符處的字符的差值。下面小編就來為大家介紹下c語言strcmp的用法。 #include <stdio.h> int stringcompare(char *source, char *target); int main() { char str_a[] = "Welcome to "; char str_b[] = "Welcome to "; int wait, result; result = stringcompare(str_b, str_a); printf("After Function Call: n"); printf("result is '%d' n", result); scanf("%d", &wait); } /* 根據 source 按照字典順序小於、等於或大於 target 的結果分別返回負整數、0或者整數 */ int stringcompare(char *source, char *target) { int i; for(i = 0; source[i] == target[i]; i++) { if (source[i] == '