#include <stdio.h>void main (void) { char * cgistr = ' | ip=192.168.1.78| port=5678| dbname=haha| user=hehe| Pwd=123456| "; Char cbusip[16]= ""; int nport = 0; Char cdbname[64] = ""; Char cuser[64] = ""; Char cpwd[64] = ""; Char cquestcmd[16]= ""; SSCANF (Cgistr, "| ip=%[^|]| port=%d| dbname=%[^|]| user=%[^|]| Pwd=%[^|]| ", Cbusip, &nport, Cdbname, Cuser, CPWD); printf (CBUSIP); printf ("\ n"); sprintf (Cquestcmd, "Hget%s_infor OWner", cdbname); printf (cquestcmd); printf ("\ n");}
Console output:
192.168.1.78
Hget haha_infor OWner
It's a sight to see.
sscanf (parameter 1, parameter 2, Parameter 3 ...) is to assign the desired field in Parameter 1 to parameter 3 by the form of parameter 2 ....
sprintf (parameter 1, parameter 2, Parameter 3 ...) is the parameter 3 ... The field is stitched to parameter 1 in the form of parameter 2.
"%n[a-z]" reads up to n characters and stops if a non-a-Z character is encountered
"%[^=]" reads any number of characters until it encounters "=" Stop
"%n[^=" reads up to n characters before the "=" sign
Use of sscanf () and sprintf () in C language