大龙的博客

常用链接

统计

最新评论

如何使用逗号 (,) 作为分隔符 sscanf() 示例


/* The following sample illustrates the use of brackets and the
   caret (^) with sscanf().
   Compile options needed: none
*/

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

char *tokenstring = "first,25.5,second,15";
int result, i;
double fp;
char o[10], f[10], s[10], t[10];

void main()
{
   result = sscanf(tokenstring, "%[^','],%[^','],%[^','],%s", o, s, t, f);
   fp = atof(s);
   i  = atoi(f);
   printf("%s\n %lf\n %s\n %d\n", o, fp, t, i);
}

posted on 2008-05-30 00:05 大龙 阅读(1962) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理