sscanf(3) Library Functions Manual sscanf(3) sscanf, vsscanf - (libc -lc) #include int sscanf(const char *restrict str, const char *restrict format, ...); #include int vsscanf(const char *restrict str, const char *restrict format, va_list ap); glibc ( feature_test_macros(7)): vsscanf(): _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L sscanf() format . format. . format . . sscanf() str. vsscanf() vsprintf(3). format . sscanf(). "" : ( ). : o ( isspace(3)). . o ( '%'). . o '%' ( ). . -- . format '%' "%n$" ( ) : o '*' : sscanf() . sscanf(). o ('). LC_NUMERIC . ( setlocale(3).) '*'. o 'm' . (%s, %c, %[) : sscanf() char * ( ). free(3) . o . . ( ) . ('\0') . . o . l %d long int. o . format '%' "%n$". format "%n$" %% %*. format '%' pointer . "%n$" ( POSIX.1-2001 C99) n pointer n format. : h d i o u x X n short unsigned short ( int). hh h signed char unsigned char. j h intmax_t uintmax_t. C99. l d i o u x X n long unsigned long ( int) e f g double ( float). %c %s . ll (-) b d i o u x X n long long unsigned long long ( int). L e f g long double ( GNU) d i o u x long long. q L. ANSI C. t h ptrdiff_t. C99. wN N (C23). z h size_t. C99. : % '%' . %% '%'. ( ) . d int. i int. 16 0x 0X 8 0 10 . . o unsigned int. u unsigned int. x ( 0x 0X ) unsigned int. X x. f float. e f. g f. E f. a (C99) f. s ('\0') . . c ( 1) char ( ). . . . [ char . . ( ) [ ]. (^). . - . . [^]0-9-] " ". ( ) . p ( %p printf(3)) void. n int ( ). . * . %*n. . EOF . EILSEQ . EINVAL format NULL. ENOMEM . attributes(7). +----------------------+------------------------------------+---------------------------------------------------------------------------------------------+ | | | | +----------------------+------------------------------------+---------------------------------------------------------------------------------------------+ |sscanf(), vsscanf() | | (locale) (MT-Safe) | +----------------------+------------------------------------+---------------------------------------------------------------------------------------------+ C11, POSIX.1-2008. C89, POSIX.1-2001. q 4.4BSD long long ll L GNU. Linux GNU libio. info(1) GNU libc (glibc-1.08) . - 'a' GNU C ( ) a. ( glibc 2.0.) sscanf() *buf: char *buf; sscanf(str, "%as", &buf); a a ISO C f ( ). POSIX.1-2008 m ( ). a gcc -std=c99 gcc -D_ISOC99_SOURCE ( _GNU_SOURCE ) a ( ). m glibc 2.7 a. POSIX m a: o %c ( %3mc). o %a ( gcc -std=c99 ). . C11 7.21.6.2/10 . ISO C . . strtol(3) . . C99 q a L ll. C99. C99 ( %Ld). . C99 q L d i o u x X ll. q 4.4BSD L. m ( %ms %m[range]). free(3) : char *p; int n; errno = 0; n = sscanf(str, "%m[a-z]", &p); if (n == 1) { printf("read: %s\n", p); free(p); } else if (errno != 0) { perror("sscanf"); } else { fprintf(stderr, "No matching characters\n"); } free(3) sscanf() . getc(3) printf(3) setlocale(3) strtod(3) strtol(3) strtoul(3) 3 . . : . 6.18 16 2026 sscanf(3)