专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > C语言

急字符串查找有关问题

发布时间:2011-06-28 16:12:47 文章来源:www.iduyao.cn 采编人员:星星草
急,字符串查找问题
#include   <stdio.h>
#include   <string.h>

int   *getPostion(char   *str,char   *findstr){
                char   *strTemp   =   str;
                static   int   pos[100];
                int   m   =   0;
                while(1)
                {
                                strTemp   =   strstr(strTemp,findstr);
                                if(NULL   ==   strTemp)
                                                break;
                                else
                                {
                                                printf( "Position:%d\r\n ",strTemp   -   str);
                                                pos[m]   =   strTemp   -   str;
                                                m++;
                                                strTemp   +=   strlen(findstr);
                                }
                }
                return   pos;
}

int   main()
{
//char   str[]   =   "hello   world,hello,helloworld,hello,hello,world! ";
char   str[]   =   "hello   world,hello,helloworld ";
char   findstr[]   =   "hello ";
int   *pos   =   getPostion(str,findstr);
printf( "size:%d\r\n ",sizeof(pos));
int   m   =   0;
for(m   =   0   ;   m   <   sizeof(pos);   m++){
                printf( "Pos:%d\r\n ",pos[m]);

}

}

我想得取findstr在str串中位置,返回一个数组
但是我返回的sizeof(pos)为什么每次都是4

请问有什么办法。。。

------解决方案--------------------
没有办法,sizeof(int *)永远都是4,sizeof(int [])也是一个定值

可以把数量存放到pos[0]
------解决方案--------------------
pos是函数的局部数组,传不出来,只能传出数组的首地址。
所以事先用一个数组专门来存放pos的信息,见以下void main()函数。

void getPostion(int pos[],char *str,char *findstr){
//对pos的数据进行修改
}

int getLen(int a[])
{
int i=0;
while (a[i++]!=0)
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: