新日记
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

1.5 KiB

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
   int day, year;
   char weekday[20], month[20], dtm[100];

   strcpy( dtm, "Saturday March 25 1989" );
   sscanf( dtm, "%s %s %d  %d", weekday, month, &day, &year );

   printf("%s %d, %d = %s\n", month, day, year, weekday );
    
   return(0);
}
int sscanf(const char *str, const char *format, ...)
参数
str -- 这是 C 字符串,是函数检索数据的源。
format -- 这是 C 字符串,包含了以下各项中的一个或多个:空格字符、非空格字符  format 说明符。
format 说明符形式为 [=%[*][width][modifiers]type=],具体讲解如下:
参数    	描述
*	           这是一个可选的星号,表示数据是从流 stream 中读取的,但是可以被忽视,即它不存储在对应的参数中。
width	   这指定了在当前读取操作中读取的最大字符数。
modifiers    为对应的附加参数所指向的数据指定一个不同于整型(针对 di  n)、无符号整型(针对 ou  x					或浮点型(针对 ef  g)的大小: h :短整型(针对 di  n),或无符号短整型(针对 ou  						x l :长整型(针对 di  n),或无符号长整型(针对 ou  x),或双精度型(针对 ef  g 					L :长双精度型(针对 ef  g
type		一个字符,指定了要被读取的数据类型以及数据读取方式。具体参见下一个表格。