// crt_sscanf_s.c // This program uses sscanf_s to read data items // from a string named tokenstring, then displays them. #include<stdio.h> #include<stdlib.h>
<!-- more --> intmain( void ) { char tokenstring[] = "15 12 14..."; char s[81]; char c; int i; float fp; // Input various data from tokenstring: // max 80 character string plus NULL terminator sscanf_s( tokenstring, "%s", s, _countof(s) ); sscanf_s( tokenstring, "%c", &c, sizeof(char) ); sscanf_s( tokenstring, "%d", &i ); sscanf_s( tokenstring, "%f", &fp ); // Output the data read printf_s( "String = %s\n", s ); printf_s( "Character = %c\n", c ); printf_s( "Integer: = %d\n", i ); printf_s( "Real: = %f\n", fp ); }