比较2个字符串是否相等。

来源:百度知道 编辑:UC知道 时间:2024/05/11 16:33:08
用C语言程序编写

我就给你写个函数好了~其他的主函数你可以自己写的很简单的!

int INDEX(String s,String p)
{
int i=0 ,j=0;
while(i<=s.length-p,length && j<p.length)
{ if(s.str[i]==p.str[j])
{ i++;j--;
}
else return;
if(j>=p.length) return;

}
}

用 strcmp(s1,s2)

if (strcmp(s1,s2) == 0) 2个字符串相等
if (strcmp(s1,s2) > 0) s1 大于 s2
if (strcmp(s1,s2) < 0) s1 小于 s2

头文件 #include <string.h>

//楼主是要下面的程序吧.......

#include <string.h>
#include <stdio.h>
int strncmp1(char* a, char* b, int n)
{
int i = 0;
if (a==0 || b==0)
return 0;/* 空指针不作处理*/
while (i<n && *(a+i) && *(b+i))
{
if (*(a+i)>*(b+i))
return 1;
if (*(a+i)<*(b+i))
return -1;
i++;
}

return 0;
}

int strcmp1(char* a, char* b)
{
int i = 0;
if (a