- 相干保举
c说话strcmp的用法
函数 int stringcompare(char *source, char *target) 比拟字符串 source 和 target,并按照 source 是不是小于、即是或大于 target 的成果别离前往负整数、0或整数。该前往值是 source 和 target 由前后逐字符比拟时碰到的第一个不相称字符处的字符的差值。上面小编就来为大师先容下c说话strcmp的用法。
#include
int stringcompare(char *source, char *target);
int main()
{
char str_a[] = "Welcome to www.nowamagic.net";
char str_b[] = "Welcome to www.nowamagic.net";
int wait, result;
result = stringcompare(str_b, str_a);
printf("After Function Call: ");
printf("result is '%d' ", 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] == '