【文件属性】:
文件名称:计算字符串长度 和 判断两个字符串是否相同
文件大小:711B
文件格式:C
更新时间:2013-04-09 08:48:29
计算字符串长度 和 判断两个字符串是否相同
练习之一
//自定义字符长度函数 和 判断两个字符串是否一致的函数
#include "stdio.h"
int len(char *p)//计算字符串长度的函数
{
int i=0;
while( *p != '\0')
{
i++;
p++;
}
return i;
}
int strsame (char *str1,char *str2)//判断两个字符串是否一致
{
int i,j;
int k=0;
i=len(str1);
j=len(str2);
if(i==j)
{
while(*str1 != '\0')
{
if (*str1==*str2) k++;
str1++;str2++;
}
if (k==i) return 1;
}
else return 0;
}
int main (void)
{
int i,j;
char shu[50],shu2[50];
scanf("%s",shu);
scanf("%s",shu2);
i=len(shu);
j=len(shu2);
printf("%d %d\n",i,j);
if (strsame(shu,shu2)==1) printf("that same\n"); else printf("that deffent");
getch();
return 0;
}