SSCANF parsing strings or file contents that conform to a certain pattern

Source: Internet
Author: User

1     Char* Pszlog ="192.168.110.98--1264348800 \ "GET http://www.xxxxxxx.cc/web/validate/captcha.php?cid=134&3307 http/1.0\" 404 534 \ "-\" \ "Trend Micro WTP add-on 1.2.1046\" Tcp_miss:first_up_parent";2 3     Charszip[ -] = {0};4     Charsztime[ -] = {0};5     Charszurl[ the] = {0};6     Charszcmd[8]   = {0};7     intNstatus;8     intNCode;9     Charszprofile[ -] = {0};Ten     Charszprotocol[ -] = {0}; One     intnRetCode; A     Charszbuf[ +] = {0}; -SSCANF (Pszlog,"%s--%s%*[\ "]%s%1000[^\"]\ "%d%d%*[\"]%1000[^\ "]\"%*[\ "]%1000[^\ "]\ "%s%d\n",  -Szip, Sztime, Szcmd, Szurl, &nstatus, &ncode, Szprofile, Szprotocol, Szbuf, &nRetCode); the  -printf"szip:[%s]\n", szip); -printf"sztime:[%s]\n", sztime); -printf"szcmd:[%s]\n", szcmd); +printf"szurl:[%s]\n", szurl); -printf"nstatus:[%d]\n", nstatus); +printf"ncode:[%d]\n", NCode); Aprintf"szprofile:[%s]\n", szprofile); atprintf"szprotocol:[%s]\n", Szprotocol); -printf"nretcode:[%d]\n", nRetCode); -printf"szbuf:[%s]\n", szbuf);

Description
The first format,%s, will fetch the IP address in the string
The second format----will skip/match "--" in a string
The third format%*[\ "], will skip a quotation mark" ""
The fourth format,%s, will present a string in the get
The fifth format,%1000[^\ "]\", extracts 1000 characters (including spaces) until the quotation mark "" ", but not the quotation marks, otherwise sccanf encounters a space stop extraction
Sixth format:%d
Seventh format:%d, this two format extracts the numbers in a string
Eighth format:%*[\ "], will skip quotation marks
Nineth format:%1000[^\ "]\", Extracts the "-" symbol from the string, and then skips the quotation marks
Tenth format:%*[\ "], will skip quotation marks
11th format:%1000[^\ "]\", will present a string in the profile
12th format:%s, the last string will be fetched
13th format:%d, the last digit will be fetched

2. Resolve the wireless router information, the AP name contains spaces

// bc:05:43:ea:fa:5b       2412    -49     [wpa2-psk-ccmp][wps][ess]       tplink 7270 format string:"  %s%*d%d%s%64[^\n]"
First format:%s, Bssid value will be extracted
Second format:%*d, will skip bandwidth value, 2.4G
Third format:%d, the signal value will be extracted
Fourth format:%s, security authentication information will be extracted
Fifth format:%64[^\n], the name of the router will be extracted until a newline symbol is encountered.

3. Parsing a particular format string

ssid= "Test_ap" /* %*[^=], skip "SSID"   * =\ "   , skip" =\ ""   *%[^\ "], get the remain string except the quota. */ "%*[^=]=\"%[^\"]"
First format string:%*[^=], the SSID will be skipped
Second format string: =\ ", matches the Equals and left quotes in the string
The third format string:%[^ "], will match TEST_AP this name

SSCANF parsing strings or file contents that conform to a certain pattern

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.