![]() |
![]() |
![]() |
Scan input from a character string
#include <stdio.h> int sscanf( const char* in_string, const char* format, ... );
libc
The sscanf() function scans input from the character string in_string, under control of the argument format. Following the format string is the list of addresses of items to receive values.
For details about the format string, see scanf().
The number of input arguments for which values were successfully scanned and stored, or EOF when the scanning is terminated by reaching the end of the input string.
#include <stdio.h> #include <stdlib.h> int main( void ) { int day, year; char weekday[20], month[20]; sscanf( "Thursday February 0025 1999", "%s %s %d %d", weekday, month, &day, &year ); printf( "%s %d, %d is a %s\n", month, day, year, weekday ); return EXIT_SUCCESS; }
produces the following:
February 25, 1999 is a Thursday
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
fscanf(), scanf(), vfscanf(), vsscanf()
![]() |
![]() |
![]() |