strcmp函数的用法

问题描述:

strcmp函数的用法
1个回答 分类:综合 2014-11-06

问题解答:

我来补答
原型:extern int strcmp(const char *s1,const char * s2); 用法:#include 功能:比较字符串s1和s2.说明:当s10 即:两个字符串自左向右逐个字符相比(按ASCII值大小相比较),直到出现不同的字符或遇'\0'为止.如:"A""A" "computer">"compare" 特别注意:strcmp(const char *s1,const char * s2)这里面只能比较字符串,不能比较数字等其他形式的参数.
编辑本段应用举例
举例1:(在VC6.0中运行通过) #include #include void main() { char string[20]; char str[3][20]; int i; for(i=0;i0) strcpy(string,str[0]); else strcpy(string,str[1]); if(strcmp(str[2],string)>0) strcpy(string,str[2]); printf("\nThe largest string is %s\n",string); } 举例2:(TC中运行通过) // strcmp.c #include #include int main() { char *s1="Hello,Programmers!"; char *s2="Hello,programmers!"; int r; clrscr(); r=strcmp(s1,s2); if(!r) printf("s1 and s2 are identical"); else if(
 
 
展开全文阅读
剩余:2000