69,381
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include<string.h>
int cmp(char* p1, char* p2)
{
int temp = 0,temp1=0;
char* p3 = p2;
for (char* p4=p1; *p1 != '\0'; p1++)
{
for (p2 = p3; *p2 != '\0'; p2++)
{
if (*p2 == *p1)
{
char* p5 = p1;
for (; (*p2 != NULL) && (*p1 != NULL); p2++, p1++)
{
if (*p2 == *p1) { temp = 1; temp1 =( p5 - p4)+1;
}
else { temp = 0; temp1 = 0; break; }
}
}
if (temp == 1)break;
}
if (temp == 1)break;
}
return temp1;
}
int main(void)
{
#include <stdio.h>
#include<string.h>
int cmp(char* p1, char* p2)
{
int temp = 0;
char* p3 = p2;
for (int i = 0; *p1!= '\0'; p1++)
{
for (p2=p3; *p2!= '\0'; p2++)
{
if (*p2 == *p1)
{
for (; (*p2 != NULL) && (*p1 != NULL); p2++,p1++)
{
if (*p2 == *p1) { temp = 1; }
else { temp = 0; break; }
}
}
}
}
return temp;
}
int main(void)
{
char digit1[10];
char digit2[10];
int i, j, temp = 0;
printf("请输入第一个数字串:\n");
gets_s(digit1);
printf("请输入第二个数字串:\n");
gets_s(digit2);
char* p1=NULL, * p2=NULL;
int a = strlen(digit1);
int b = strlen(digit2);
if (strlen(digit1) <=strlen(digit2))
{
p1 = digit2;
p2 = digit1;
}
else
{
p1 = digit1;
p2 = digit2;
}
temp = cmp(p1, p2);
printf("%d", temp);
return 0;
}