ChinaUnix.net
相关文章推荐:

strstr函数 源代码

最近想写个小程序用到了strstr(),资料和很论谈中都有提到这个函数,反回值应是想要查找的字符第一次出现的地地址,我要试了几次反回值都是要查找的字符和它后面的字符,不知为什么,哪位帮忙 main() { char *s ="0123456789012345678901234567890"; char *p; p =strstr(s,'5'); printf("%s\n",p); } 实际返回值是:56789012345678901234567890

by chinawang - C/C++ - 2006-07-20 18:58:28 阅读(9758) 回复(5)

相关讨论

不使用已有的系统调用或函数库,实现c库的函数:strstr() 实现的原型为 char *my_strstr(char *haystack, char *needle); 返回needle字符串在haystack字符串第一次出现位置的指针,如果不存在 返回NULL。 哪个高手帮忙做一下呀。我做了1天了 都没有实现

by jxg945 - C/C++ - 2007-09-01 00:38:48 阅读(11589) 回复(65)

我有一个两个txt文件一个是配置文件,还有一个是要比较文件内容如下: peizhi.txt usedpercent /dev/cciss/c0d0p1 90 /dev/cciss/c0d0p1 53 /dev/cciss/c0d0p2 90 /dev/cciss/c0d0p2 6 none 90 ...

by superjimmy888 - C/C++ - 2009-03-04 10:28:16 阅读(850) 回复(3)

I am sorry I can't type Chinese right now. My question is ,why after executing the following code, a "segment error" occured ? Plz answer me in Chinese . Thx! :D #include #include int main() { char Search[50] ="I like XH,but she doesn't like me"; char* sub_str= Search; char* p = strstr(sub_str,"e"); *p = '\0'; p...

by wilbur8415 - C/C++ - 2008-04-07 20:45:24 阅读(1105) 回复(3)

现在有这样一个文件,其内容如下: >>>>>>>>>>>>>>>One Over[20060907-083448]<<<<<<<<<<<<<<<<< read ackhead. i=95 == headlen=95= AckPktHead.len =124= AckPktHead.factorycode == AckPktHead.progid =5= AckPktHead.morepkt = = AckPktHead.cmd_id =10012= AckPktHead.start_num =0= AckPktHead.end_num =0= AckPktHead.request_id =186= AckPktHead.answer_id ...

by lostiger - C/C++ - 2006-11-16 19:24:23 阅读(2226) 回复(9)

#include; #include; int main() { char * s="01234567890123456789012345678901"; char *p,*p1; p= strstr(s,"901"); printf("%s\n",p); p1=strstr(p,"901"); printf("%s\n",p1); return 0; } 我想使p1指向“9012345678901”, 可还是指向“90123456789012345678901”,why?

by hhlcjcj - C/C++ - 2005-10-11 00:22:11 阅读(1298) 回复(6)

有一字符串“sthx=xxx|sthss=xyx|sthyy=xyyy”,怎么样才可以通过“sthx”来得到他的值“xxx”,写一函数来实现?

by yujf - C/C++ - 2004-01-08 15:01:39 阅读(1106) 回复(3)

char *tmp=0; if((tmp=strstr(choic,"."))!=NULL) { sscanf(tmp+1,"%d",&p_num); tmp[0]='\0'; } 内存泄漏 但改成tmp='\0'; 则正确。 为什么?

by greatho1507 - C/C++ - 2008-08-16 12:31:13 阅读(7707) 回复(39)

有一个贴子http://bbs.chinaunix.net/thread-588892-1-1.html 题目是“不使用以有的系统调用或函数库实现strstr()”,有人贴了如下代码 #include #include char *my_strstr(char *,char *); int main(int argc,char *argv[]) {         char *presult;         if(3!=argc){        &n...

by ruoyisiyu - C/C++ - 2007-09-30 08:48:37 阅读(5554) 回复(5)

[code] #include; #include; int main(){//求字符串"ab"在string中出现的次数; char *string = "sdfabsdfsdabfsdfabkhjk"; char *p; int i = 0; for(p = string; p != NULL; i++){ p = strstr(p, "ab"); p = p+2; } printf("%d\n", i); return 0; } [/code] gcc test.c 竟然没warning

by FreeGnu - C/C++ - 2004-11-15 20:06:21 阅读(3113) 回复(17)

string strstr ( string haystack, string needle ) 如果needle为数组时,会如何替换,过程是什么? 请高人给我讲一下! 谢谢!

by zhanglp888 - PHP - 2006-12-10 00:09:22 阅读(1336) 回复(7)