码迷,mamicode.com
首页 >  
搜索关键字:c语言面试题 模拟实现strstr函数    ( 6个结果
C语言模拟实现strstr函数,strrstr 函数
strstr和strrstr已经算是字符串中相对比较难的了,但是只要我们善于分析,解剖字符串,就会化难为易。其实学习代码的过程中需要我们静下心来分析,理解。srtstr函数的功能及用法原型:char*strstr(constchar*dst,constchar*src);#include<string.h>找出src字符串在dst字..
分类:编程语言   时间:2017-10-26 23:13:35    阅读次数:308
模拟实现strstr函数
写一个函数,模拟strstr()函数,strstr()函数主要将主串中子串,以及以后的字符全部返回。比如:在abbcdeef中查找bcde,返回bcdeef思想:1.遍历整个长串,然后找到与短串相同的位置,并且记录这个位置2.与短串依次比较,若在后面某个位置不相同了,这时候,将刚记录的长串的位..
分类:其他好文   时间:2016-07-23 21:24:35    阅读次数:163
模拟实现strstr函数。
//1.模拟实现strstr函数。 #include<stdio.h> #include<assert.h> char*my_strstr(char*str,char*p) { char*cp=p; char*p1=str; assert(*p); if(!*p) returnNULL; if(!*p1) returnNULL; char*p2=str; while(*p1) { p2=p1; cp=p; while(*p2&&*cp&&!..
分类:其他好文   时间:2016-04-08 15:26:59    阅读次数:114
.模拟实现strstr函数
模拟实现strstr函数intmain() { char*p1,*p2; chara1[]="abbbcd"; chara2[]="bcd"; p1=a1; p2=a2; while(*p1!=‘\0‘); { if(*p1!=*p2) { p1++; if(p2!=a2) p2=a2; } else { p1++; p2++; } } if(*p2==‘\0‘) printf("Exist\n"); else p..
分类:其他好文   时间:2016-03-22 06:41:40    阅读次数:222
【C语言】【面试题】【笔试题】模拟实现strstr函数
#define_CRT_SECURE_NO_WARNINGS1 #include<stdio.h> #include<assert.h> #include<stdlib.h> char*my_strstr(constchar*dst,constchar*src) { assert(dst); assert(src); char*p=dst; char*s1=p; char*s2=src; while(*s1) { s1=p; s2=src; while((*s1!=‘\0..
分类:编程语言   时间:2015-11-20 00:20:26    阅读次数:273
模拟实现strstr函数
char*my_strstr(char*str1,char*str2){assert(str1);assert(str2);char*p=str1;char*pstr1=p;char*pstr2=NULL;while(*pstr1){pstr1=p;pstr2=str2;while(*pstr1&&*pstr2&&*pstr1==*pstr2){pstr1++;pstr2++;}if(*pstr2==‘\0‘){returnp;}p++;}returnNULL;}
分类:其他好文   时间:2015-11-10 01:52:03    阅读次数:186
6条  
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!