码迷,mamicode.com
首页 > 其他好文 > 详细

C字符串题目

时间:2016-04-01 22:01:58      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

 

技术分享

 

 

#include<stdlib.h>
#include<stdio.h>
char* string_in(char *s1,char *s2)
{
char *temp1=s1;
char *temp2=s2;
char *temp=s1;
int inword;

while(*s2!=‘\0‘&&*s1!=‘\0‘)
{
if(*s1==*s2)
{
inword=1;
s1++;
s2++;
}
else
{
inword=0;
s1++;
s2=temp2;
}
if(!inword)
{
temp=s1;
}

}
if(*s2==‘\0‘&&inword)
return temp;
else
return NULL;

}

int main()
{
while(1)
{
char a[30],b[30];
printf("字符串1\n");
gets(a);
printf("字符串2\n");
gets(b);
char *c=string_in(a,b);
if(c)
printf("包含\n");
else
printf("不包含\n");
printf("字符串1包含的开始地址为%p,字母为%c\n",c,*c);
}

}

C字符串题目

标签:

原文地址:http://www.cnblogs.com/HJL085/p/5346358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!