自己做了一个strcmp()函数,老师布置滴作业,感觉有点繁杂,谁能帮偶简化一下,还有,那个数组规定了数组是100个,有没有不限制的?麻烦看看,谢谢啦~~·
#include"stdio.h"
char mystrcmp(char *str1,char *str2)
{
char a[100],b[100];
int i=0,sum1=0,sum2=0;
for(;*str1!='\0';str1++,i++)
{
a[i]=*str1;
sum1+=a[i];
}
for(;*str2!='\0';str2++,i++)
{
b[i]=*str2;
sum2+=b[i];
}
if(sum1>sum2)
{
return 1;
}
if(sum1<sum2)
{
return -1;
}
if(sum1==sum2)
{
return 0;
}
}
void main()
{
char a[15],b[15];
printf("\nplease input username:");
gets(a);
printf("please input password:");
gets(b);
if((mystrcmp(a,"john")==0)&&(mystrcmp(b,"12345")==0))
printf("\nyou have success log in:\n");
else
printf("\nusername or password invalidation \n");
}
[求助]我这个自定义函数还能简化吗?