strcmp()函数的使用问题.docVIP

  • 8
  • 0
  • 约1.2千字
  • 约 3页
  • 2017-06-11 发布于广东
  • 举报
strcmp()函数的使用问题

使用strcmp()函数时常出现的问题 原型:int strcmp(char *str1,char *str2) 功能:把两字符串str1与str2进行比较,当str1str2,函数返回1,当str1==str2时,函数返回0,当str1str2时函数返回-1; 1)首先我们对该函数的功能进行实现一下 include stdio.h #include stdlib.h #include string.h int main() { printf(a与b的比较的结果:%d\n,strcmp(a,b)); printf(b与a的比较的结果:%d\n,strcmp(b,a)); printf(a与a的比较的结果:%d\n,strcmp(a,a)); return 0; } 执行结果: 功能相符。 2)问题引入 首先我们来看如下的编程 #include stdio.h #include stdlib.h #include string.h int main() { char str1[2],str2[2]; printf(请输入第一个字符串:); scanf(%s,str1); printf(请输入第二个字符串:) scanf(%s,str2); printf(%d,strcmp(str1,s

文档评论(0)

1亿VIP精品文档

相关文档