新日记
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.

32 lines
1.5 KiB

3 years ago
  1. ```c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. int main()
  6. {
  7. int day, year;
  8. char weekday[20], month[20], dtm[100];
  9. strcpy( dtm, "Saturday March 25 1989" );
  10. sscanf( dtm, "%s %s %d %d", weekday, month, &day, &year );
  11. printf("%s %d, %d = %s\n", month, day, year, weekday );
  12. return(0);
  13. }
  14. ```
  15. ```c
  16. int sscanf(const char *str, const char *format, ...)
  17. 参数
  18. str -- 这是 C 字符串,是函数检索数据的源。
  19. format -- 这是 C 字符串,包含了以下各项中的一个或多个:空格字符、非空格字符 和 format 说明符。
  20. format 说明符形式为 [=%[*][width][modifiers]type=],具体讲解如下:
  21. 参数 描述
  22. * 这是一个可选的星号,表示数据是从流 stream 中读取的,但是可以被忽视,即它不存储在对应的参数中。
  23. width 这指定了在当前读取操作中读取的最大字符数。
  24. modifiers 为对应的附加参数所指向的数据指定一个不同于整型(针对 d、i 和 n)、无符号整型(针对 o、u 和 x) 或浮点型(针对 e、f 和 g)的大小: h :短整型(针对 d、i 和 n),或无符号短整型(针对 o、u 和 x) l :长整型(针对 d、i 和 n),或无符号长整型(针对 o、u 和 x),或双精度型(针对 e、f 和 g) L :长双精度型(针对 e、f 和 g)
  25. type 一个字符,指定了要被读取的数据类型以及数据读取方式。具体参见下一个表格。
  26. ```