标签:cdb lin sscanf int sip Owner 字符 cgi clu
#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"); }
控制台输出:
192.168.1.78
hget haha_Infor OWner
这么一看就明白了吧。
sscanf(参数1,参数2,参数3...)是将参数1中想要的字段通过参数2的形式赋值给参数3... 。
sprintf(参数1,参数2,参数3...)是将参数3...的字段以参数2的形式拼接到参数1。
"%n[a-z]" 读入最多n个字符,如果遇到非a-z的字符,停止
"%[^=]" 读入任意多的字符,直到遇到"="停止
"%n[^=]" 读入"="号前的至多n 个字符
标签:cdb lin sscanf int sip Owner 字符 cgi clu
原文地址:https://www.cnblogs.com/airduce/p/9014927.html