sscanf函数拆分字符串

  1 #include                                                                                           
  2 #include
  3 #include
  4 int main()
  5 {
  6     char data[64] = {"{\"nvr_ip\":\"192.168.1.143\",\"nvr_diskusage\":\"normal\"}"};
  7     printf("%s\n",data);
  8     char nvr_ip[32],nvr_diskusage[32];
  9
 10     sscanf(data,"{%[^,],%[^}]}",nvr_ip,nvr_diskusage);
 11     printf("%s\n",nvr_ip);
 12     printf("%s\n",nvr_diskusage);
 13
 14     char recv_ip[32];
 15     sscanf(nvr_ip,"%*[^:]:%s",recv_ip);
 16     printf("%s   %ld\n",recv_ip,strlen(recv_ip));
 17
 18     char recv_diskusage[32];
 19     sscanf(nvr_diskusage,"%*[^:]:%s",recv_diskusage);
 20     printf("%s    %ld\n",recv_diskusage,strlen(recv_diskusage));
 21
 22     char ip[32];
 23     sscanf(recv_ip,"\"%[^\"]",ip);
 24     printf("%s\n",ip);
 25
 26     char diskusage[32];
 27     sscanf(recv_diskusage,"\"%[^\"]",diskusage);
 28     printf("%s\n",diskusage);
 29 }

创新互联公司于2013年创立,先为包河等服务建站,包河等地企业,进行企业商务咨询服务。为包河企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

sscanf函数拆分字符串


网站名称:sscanf函数拆分字符串
新闻来源:http://pwwzsj.com/article/iejpsh.html