How To sscanf() Example Using a Comma (,) as Delimiter

개발/프로그래밍2008. 10. 23. 01:31
728x90

sscanf()의 예제이다. 

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

#include 
#include 
#include 

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);
}

참조사이트



728x90

작성자

Posted by 일퍼센트

관련 글

댓글 영역