题目:编写程序,实现strcmp()相同功能myStrcmp()函数

xiaoxiao2021-02-27  676

题目:编写程序,实现strcmp()相同功能myStrcmp()函数

strcmp函数  其一般形式为:strcmp(字符串1,字符串2)  strcmp的作用是比较字符串1和字符串2。 例如:strcmp(str1,str2);       strcmp(″China″,″Korea″);       strcmp(str1,″Beijing″);

比较的结果由函数值带回 (1) 如果字符串1=字符串2,函数值为0。 (2) 如果字符串1>字符串2,函数值为一正整数。 (3) 如果字符串1<字符串2,函数值为一负整数。 注意:对两个字符串比较,不能用以下形式: if(str1>str2)  printf(″yes″); 而只能用 if(strcmp(str1,str2)>0)  printf(″yes″);

转载请注明原文地址: https://www.6miu.com/read-408.html

最新回复(0)