编程菜鸟的日记-初学尝试编程-编写函数实现strcmp功能

#include <iostream>
using namespace std;
int mystrcmp(const char *str1,const char *str2)
{
 assert(*str1!='\0' && *str2!='\0');
 while(*str1!='\0' && *str2!='\0' && *str1==*str2)
 {
  str1++;
  str2++;
 }
 return *str1-*str2;
}
int main()
{
 char str1[]=" ";
 char str2[]="abc";
 int a=mystrcmp(str1,str2);
 cout<<a<<endl;
 system("pause");
 return 0;
}

 

posted @ 2013-11-06 10:08  编程的爬行者  阅读(320)  评论(0编辑  收藏  举报