免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 2567 | 回复: 14
打印 上一主题 下一主题

求一个拆字符串的写法(要效率高一些) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-27 15:15 |只看该作者 |倒序浏览
例如:0|2304|1|1|031186342880|82147386342881|86342881|2001|127|03111234561|20060315190842|20060315190846|1|300||67|2006030400|1|3|
这里一行字符串,他们是用"|"分割,
现求一个算法以这个"|"做分隔符,最后结果写到一个数组里即可,各位大哥帮帮忙吧

论坛徽章:
0
2 [报告]
发表于 2006-04-27 15:35 |只看该作者
这两天全是这个问题,你们是不是都是老师给统一安排的作业呀!
strstr
or
strtok

论坛徽章:
0
3 [报告]
发表于 2006-04-27 15:42 |只看该作者
能不能给一些例子

论坛徽章:
0
4 [报告]
发表于 2006-04-27 15:46 |只看该作者
连一个简单的函数都要例子的话,楼主怎么培养自学能力?

论坛徽章:
0
5 [报告]
发表于 2006-04-27 15:48 |只看该作者
俺现在是一个初学者,请多包涵

论坛徽章:
0
6 [报告]
发表于 2006-04-27 15:48 |只看该作者
要例子,可以到本版搜一下,多得不能再多了

论坛徽章:
0
7 [报告]
发表于 2006-04-27 15:51 |只看该作者
我都找了好久了,都没有找到

论坛徽章:
0
8 [报告]
发表于 2006-04-27 16:00 |只看该作者
SYNOPSIS
       #include <string.h>

       char *strstr(const char *haystack, const char *needle);

DESCRIPTION
       The  strstr() function finds the first occurrence of the substring nee-
       dle in the string haystack.  
RETURN VALUE
       The  strstr()  function  returns a pointer to the beginning of the sub-
       string, or NULL if the substring is not found.


SYNOPSIS
       #include <string.h>
       char *strtok(char *s, const char *delim);
DESCRIPTION
       The strtok() function can be used to parse the string  s  into  tokens.
       The  first call to strtok() should have s as its first argument. Subse-
       quent calls should have the first  argument  set  to  NULL.  Each  call
       returns  a  pointer  to the next token, or NULL when no more tokens are
       found.

       If a token ends with a delimiter, this delimiting  character  is  over-
       written  with a \0 and a pointer to the next character is saved for the
       next call to strtok().  The delimiter string delim may be different for
       each call.

       The  strtok_r()  function  is a reentrant version of the strtok() func-
       tion, which instead of using its own static buffer, requires a  pointer
       to  a user allocated char*. This pointer, the ptrptr parameter, must be
       the same while parsing the same string.

或者楼主到baidu google  随便一搜

论坛徽章:
0
9 [报告]
发表于 2006-04-27 16:20 |只看该作者
原帖由 mike_chen 于 2006-4-27 15:35 发表
这两天全是这个问题,你们是不是都是老师给统一安排的作业呀!
strstr
or
strtok

应该是strchr吧

论坛徽章:
0
10 [报告]
发表于 2006-04-27 16:24 |只看该作者
int split(char sp, char *line, char **lst, int lst_len)
{
    int i;
    lst[0] = line;
    for (i=1; *line; line++)
    {
            if (*line == sp)
            {
                *line = '\0';
                if (i >= lst_len) break;
                    lst[i++] = line + 1;
            }
    }
    return i;
}

char *pList[80];
split('|',src,pList,80);
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP