sscanf

/****************************************************************************
@File Name: test.cpp
@Author: wangzhicheng
@mail: 2363702560@qq.com
@Created Time: Sat 04 Feb 2017 12:58:48 AM CST
****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
static const int LEN = 512;
char origin[LEN] = "58.56.110.98 -- 1264348800 \"GET http://www.baidu.com/web/validate/captcha.php?cid=134&3307 HTTP/1.0\" 404 534 \"-\" \"Micro Soft WTP Add-On 1.2.1046\" TCP_MISS:FIRST_UP_PARENT 13";
char p0[LEN] = "";
char p1[LEN] = "";
char p2[LEN] = "";
char p3[LEN] = "";
char p4[LEN] = "";
char p5[LEN] = "";
char p6[LEN] = "";
char p7[LEN] = "";
char p8[LEN] = "";
char p9[LEN] = "";
char p10[LEN] = "";
int main(int argc, char **argv)
{
	sscanf(origin, "%s --%s %*[\"]%s %s %[^\"]\" %s%s %*[\"|-] \"%[^\"]\"%s%s", p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
	// p0 -- 58.56.110.98 
	// p1 -- 1264348800
	// p2 -- GET
	// p3 -- http://... 
	// p4 -- HTTP/1.0
	// p5 -- 404
	// p6 -- 534
	// p7 -- Trend Micro WTP Add-On 1.2.1046
	// p8 -- TCP_MISS:FIRST_UP_PARENT
	// p9 -- 13
	cout << p0 << endl;
	cout << p1 << endl;
	cout << p2 << endl;
	cout << p3 << endl;
	cout << p4 << endl;
	cout << p5 << endl;
	cout << p6 << endl;
	cout << p7 << endl;
	cout << p8 << endl;
	cout << p9 << endl;

	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值