首页 > 其他 > 详细

自己实现的strcmp函数

时间:2014-11-26 06:40:28      阅读:254      评论:0      收藏:0      [点我收藏+]
#include <iostream>
using namespace std;
// 自己实现strcmp函数


int Strcmp(char to[], char from[]);
int main()
{
char to[30], from[30];
int flag;
cout << "请输入第一个字符串:";
cin >> to;
cout << "请输入第二个字符串:";
cin >> from;
flag = Strcmp(to, from);
if (1 == flag)
cout << to << "大于" << from << endl;
else if (0 == flag)
cout << to << "等于" << from << endl;
else
cout << to << "小于" << from << endl;
system("pause");
return 0;
}


int Strcmp(char to[], char from[])
{
int i = 0;
for (; ‘\0‘ != to[i]  && ‘\0‘ != from[i]; i++)
if (to[i] > from[i])
return 1;
else if (to[i] < from[i])
return -1;
if (‘\0‘ == to[i])
return -1;
else if (‘\0‘ == from[i])
return 1;
else
return 0;
}

自己实现的strcmp函数

原文:http://blog.csdn.net/fantasydreams/article/details/41505949

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!