| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 417 人关注过本帖
标题:请各位大侠帮忙编写个程序,在字符串str1中找指定的字符串str2,并返回str2 ...
只看楼主 加入收藏
bclt2009
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2009-7-24
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
请各位大侠帮忙编写个程序,在字符串str1中找指定的字符串str2,并返回str2在str1中首次找到的位置。
如题,请各位大侠帮帮忙!
搜索更多相关主题的帖子: 编程问题 
2009-07-24 21:20
airhiphop
Rank: 4
来 自:江苏南通
等 级:业余侠客
帖 子:69
专家分:256
注 册:2007-11-16
收藏
得分:10 
我弄了一个,不过感觉还有更改的地方
https://bbs.bccn.net/thread-280363-1-1.html
你看看吧

2009-07-24 21:23
prankmoon
Rank: 8Rank: 8
等 级:蝙蝠侠
帖 子:161
专家分:921
注 册:2009-7-21
收藏
得分:10 
Find a substring.

char *strstr( const char *string, const char *strCharSet );

程序代码:
/* STRSTR.C  from MSDN */

#include <string.h>
#include <stdio.h>

char str[] =    "lazy";
char string[] = "The quick brown dog jumps over the lazy fox";
char fmt1[] =   "         1         2         3         4         5";
char fmt2[] =   "12345678901234567890123456789012345678901234567890";

void main( void )
{
   char *pdest;
   int  result;
   printf( "String to be searched:\n\t%s\n", string );
   printf( "\t%s\n\t%s\n\n", fmt1, fmt2 );
   pdest = strstr( string, str );
   result = pdest - string + 1;
   if( pdest != NULL )
      printf( "%s found at position %d\n\n", str, result );
   else
      printf( "%s not found\n", str );
}


Output

String to be searched:
   The quick brown dog jumps over the lazy fox
            1         2         3         4         5
   12345678901234567890123456789012345678901234567890

lazy found at position 36
2009-07-25 02:52
快速回复:请各位大侠帮忙编写个程序,在字符串str1中找指定的字符串str2,并返回 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012070 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved