免费注册 查看新帖 |

Chinaunix

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

字符串问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-01-16 18:51 |只看该作者 |倒序浏览
将用文件分隔符‘|’分开的长串以分隔符为分隔点,分别付给多个对应变量,方法要简洁,那位大虾有高见

论坛徽章:
0
2 [报告]
发表于 2004-01-16 22:03 |只看该作者

字符串问题

你这句话能不能先说清楚一点呀,把意思说得明白一点

论坛徽章:
0
3 [报告]
发表于 2004-01-17 14:24 |只看该作者

字符串问题

举个例子
string=f|g|h|i|j|k|||
把string以'|'为分隔点分开,分别付值给s1,s2,s3,s4等,
s1=f;
s2=g;
s3=i;
...

论坛徽章:
0
4 [报告]
发表于 2004-01-17 14:34 |只看该作者

字符串问题

关键是要是假如h等字符串本身就包涵“|"那怎么办?

论坛徽章:
0
5 [报告]
发表于 2004-01-17 15:05 |只看该作者

字符串问题

用strtok()函数试试

论坛徽章:
0
6 [报告]
发表于 2004-01-17 15:34 |只看该作者

字符串问题

while(strtok(null,"|"){
}

论坛徽章:
0
7 [报告]
发表于 2004-01-20 12:06 |只看该作者

字符串问题

scanf("%s|%s|%s",f,g,h);

论坛徽章:
0
8 [报告]
发表于 2004-01-20 16:47 |只看该作者

字符串问题

source from MSDN
/* STRTOK.C: In this program, a loop uses strtok
* to print all the tokens (separated by commas
* or blanks) in the string named "string".
*/

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

char string[] = "A string\tof ,,tokens\nand some  more tokens";
char seps[]   = " ,\t\n";
char *token;

void main( void )
{
   printf( "%s\n\nTokens:\n", string );
   /* Establish string and get the first token: */
   token = strtok( string, seps );
   while( token != NULL )
   {
      /* While there are tokens in "string" */
      printf( " %s\n", token );
      /* Get next token: */
      token = strtok( NULL, seps );
   }
}


Output

A string   of ,,tokens
and some  more tokens

Tokens:
A
string
of
tokens
and
some
more
tokens
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP