sscanf
Language/C 2012. 5. 29. 10:33다음 예제에서는 구분 쉼표 (,) 필드와 내부 버퍼에서 읽을 sscanf() C 런타임 함수를 사용하는 방법을 보여 줍니다. 키가 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);
}
'Language > C' 카테고리의 다른 글
가변인수 va_start() (0) | 2012.06.11 |
---|---|
typedef & struct (2) (0) | 2012.05.29 |
typedef & struct (1) (0) | 2012.05.23 |
inconv source (iconv_open, iconv, iconv_close) (0) | 2012.05.16 |
inconv.h (0) | 2012.05.16 |