免费注册 查看新帖 |

Chinaunix

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

[故障求助] 有个弱智的问题想问 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-07-31 15:55 |只看该作者 |正序浏览
有一按一定格式定义的字符串,如“ 123456789|1970-01-23|108|34.56|中国”,能否方便地将其中123456789,1970-01-23,108,34.56,“中国”等赋于一些事先定义好的变量。谢谢

论坛徽章:
0
12 [报告]
发表于 2003-08-20 11:49 |只看该作者

有个弱智的问题想问

[quote]原帖由 "backhead"]能否详细说说strtok的用法[/quote 发表:
     

eg: "I like this place, hehe, "

pstr = strtok("I like this place, hehe, ", ",";
//pstr == "I like this place"
pstr = strtok('\0', ",";
//pstr == "hehe"

论坛徽章:
0
11 [报告]
发表于 2003-08-20 09:31 |只看该作者

有个弱智的问题想问

如果系统安装了man中的Technical Reference(一般命令帮助是Command Reference),用man 2 strtok命令就可以看。

char *strtok (String1, String2)
char *String1;
const char *String2;

Attention: Do not use the strtok subroutine in a multithreaded environment.

The strtok subroutine breaks the string pointed to by the String1 parameter into a sequence of tokens, each of which is delimited by a byte from the string pointed to by the String2 parameter. The first call in the sequence takes the String1 parameter as its first argument and is followed by calls that take a null pointer as their first argument. The separator string pointed to by the String2 parameter may be different from call to call.

The first call in the sequence searches the String1 parameter for the first byte that is not contained in the current separator string pointed to by the String2 parameter. If no such byte is found, no tokens exist in the string pointed to by the String1 parameter, and a null pointer is returned. If such a byte is found, it is the start of the first token.

The strtok subroutine then searches from the first token for a byte that is contained in the current separator string. If no such byte is found, the current token extends to the end of the string pointed to by the String1 parameter, and subsequent searches for a token return a null pointer. If such a byte is found, the strtok subroutine overwrites it with a null byte, which terminates the current token. The strtok subroutine saves a pointer to the following byte, from which the next search for a token will start. The subroutine returns a pointer to the first byte of the token.

Each subsequent call with a null pointer as the value of the first argument starts searching from the saved pointer, using it as the first token. Otherwise, the subroutine's behavior does not change.

论坛徽章:
0
10 [报告]
发表于 2003-08-20 09:23 |只看该作者

有个弱智的问题想问

能否详细说说strtok的用法

论坛徽章:
0
9 [报告]
发表于 2003-08-19 21:13 |只看该作者

有个弱智的问题想问

[quote]原帖由 "larryh"]合成简单,分开一般要写程序。这程序也不复杂,无非是在字符串里查找特定字符(如“|”),根据位置,取子字符串存在别的指针里,将原字符串指针移动到“|”后面的部分,重复做这个动作,直到找不到更多的“|”为止?.........[/quote 发表:
     

顶。strtok

论坛徽章:
0
8 [报告]
发表于 2003-08-19 17:44 |只看该作者

有个弱智的问题想问

哈哈,我知道用scanf可以的

论坛徽章:
0
7 [报告]
发表于 2003-08-05 18:16 |只看该作者

有个弱智的问题想问

合成简单,分开一般要写程序。这程序也不复杂,无非是在字符串里查找特定字符(如“|”),根据位置,取子字符串存在别的指针里,将原字符串指针移动到“|”后面的部分,重复做这个动作,直到找不到更多的“|”为止。如果域数目数目不定或太多,要用到字符串指针数组。

有一个函数:strtok也可以达到这个目的,典型用途是分析命令行参数,可以参考。

论坛徽章:
0
6 [报告]
发表于 2003-08-05 18:10 |只看该作者

有个弱智的问题想问

可能是我没表述清楚。C语言里有sprintf(str,"%s|%d|%s\n",s1,d1,s2)这样的语句,生成一个用“|”分隔的字符串str,我的意思是说如果有了str,能否用类似的语句把str解析出s1,d1,s2?
uuutuo 该用户已被删除
5 [报告]
发表于 2003-08-02 01:27 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
4 [报告]
发表于 2003-08-01 08:17 |只看该作者

有个弱智的问题想问

[quote]原帖由 "backhead"]忘了说了,用C语言[/quote 发表:
     
C语言就用字符串处理阿!
  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP