This function is really powerful, and this essay will always update some summaries until most of the applications are covered:
EG1:
A string---"+cbc:0,90,4090" from the cloud in the company project today
I want to get the number 0,90,4090. Of course, we can write a function, judge, and each value, and then mix into the desired data, but this is really too troublesome, so sscanf came.
#include <stdio.h>intMainvoid){ intA; intb; intC; Char*s="+cbc:0,90,4090"; SSCANF (s),"+CBC:%d,%d,%d",&a,&b,&c); printf ("%d%d%d\n", A,b,c); return 0;}
is not very simple to complete the string in the extraction of numbers, and you can format the input.
It should be noted that the corresponding clear, the above string +CBC: (space) So in the sscanf also must correspond, the space others have, you have to have, there is the time of the format, if in the form of character input, can only read a byte (of course, char is a byte of the machine).
#include <stdio.h>intMainvoid){ intA; intb; CharC; Char*s="+cbc:0,90,4090"; SSCANF (s),"+CBC:%d,%d,%c ",&a,&b,&c); printf ("%d%d%c\n", A,b,c); return 0;}
Above the red part, just change to the form%c, the output will only have one byte:
SSCANF far more than this role, more to be continued ...
sscanf function--powerful C library function