sscanf command

简介:

这个网站里面包含了所以得C库,方便查找笔记,http://www.cplusplus.com/reference/cstdio/sscanf/kw=sscanf

function
<cstdio>

sscanf

int sscanf ( const char * s, const char * format, ...);
Read formatted data from string
Reads data from s and stores them according to parameter format into the locations given by the additional arguments, as if scanf was used, but reading from s instead of the standard input (stdin).

The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier within the format string.

Parameters

s
C string that the function processes as its source to retrieve the data.
format
C string that contains a format string that follows the same specifications as format in scanf (see scanf for details).
... (additional arguments)
Depending on the format string, the function may expect a sequence of additional arguments, each containing a pointer to allocated storage where the interpretation of the extracted characters is stored with the appropriate type.
There should be at least as many of these arguments as the number of values stored by the format specifiers. Additional arguments are ignored by the function.

Return Value

On success, the function returns the number of items in the argument list successfully filled. This count can match the expected number of items or be less (even zero) in the case of a matching failure.
In the case of an input failure before any data could be successfully interpreted, EOF is returned.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* sscanf example */
#include <stdio.h>

int main ()
{
  char sentence []="Rudolph is 12 years old";
  char str [20];
  int i;

  sscanf (sentence,"%s %*s %d",str,&i);
  printf ("%s -> %d\n",str,i);
  
  return 0;
}


Output:
Rudolph -> 12

目录
相关文章
|
6月前
|
安全 C语言
snprintf的用法
简要介绍了snprintf的常用方法,能大大的简化我们的代码
|
5月前
|
C语言
【C语言】:浅谈函数 fscanf/sscanf 和 fprintf/sprintf
【C语言】:浅谈函数 fscanf/sscanf 和 fprintf/sprintf
57 1
|
6月前
gets()&puts()函数
gets()&puts()函数。
36 2
|
6月前
|
机器学习/深度学习
fprintf()函数和fwrite()函数
fprintf()函数和fwrite()函数
71 1
|
6月前
|
C语言
文件操作(二、scanf/fscanf/sscanf​与printf/fprintf/sprintf​、fseek与ftell与rewind、feof)
文件操作(二、scanf/fscanf/sscanf​与printf/fprintf/sprintf​、fseek与ftell与rewind、feof)
|
C语言
【C语言】scanf/fscanf/sscanf和printf/fprintf/sprintf的详细介绍
【C语言】scanf/fscanf/sscanf和printf/fprintf/sprintf的详细介绍
fgets(),strtod(),strnlen(),strcmp()函数记录
fgets(),strtod(),strnlen(),strcmp()函数记录
|
编译器 C++
文件操作以及相关的函数,fputc,fgetc,fputs,fgtes,fprintf,fscanf,sprintf,sscanf
🐰文件操作 🌸打开文件 🏡文件的顺序读写 🌸fputc字符输入函数(适合所有输入流) 🌸fgetc(适合所有的输出流) 🌸fputs(适合所有的输入流) 🌸fgets(适合所有的输出流) 🏡格式化的读写 🌸fprintf(适合所有的输入流) 🌸fscanf读取文件(适合所有的输出流) 🏡流 🌸屏幕这个流(stdout)输出 🏡对比:printf/fprintf/sprintf和scanf/fscanf/sscanf 🌸sprintf(把格式化数据转换成字符串) 🌸sscanf(把字符串转换成相应格式化数据)
scanf fscanf sscanf printf fprintf sprintf的区别和使用 fseek的使用
scanf fscanf sscanf printf fprintf sprintf的区别和使用 fseek的使用
121 0