SSCANF sprintf Sstream

Source: Internet
Author: User

1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4   5 Static voidSscanf_test (void); 6   7 Static voidSscanf_test (void)  8 {  9     intret; Ten     Char*string;  One     intDigit;  A     Charbuf1[255];  -     Charbuf2[255];  -     Charbuf3[255];  the     Charbuf4[255];  -    -     /*1. The simplest usage*/   -     string="China Beijing 123";  +ret = SSCANF (string,"%s%s%d", Buf1, Buf2, &digit);  -printf"1.string=%s\n",string);  +printf"1.ret=%d, buf1=%s, buf2=%s, digit=%d\n\n", ret, BUF1, buf2, digit);  A     /*  at * * Results of execution: - **1.ret=3, Buf1=china, buf2=beijing, digit=123 - * * It can be seen that the return value of SSCANF is the number of parameters read -     */   -    -     /*2. Take a string of the specified length*/   in     string="123456789";  -sscanfstring,"%5s", BUF1);  toprintf"2.string=%s\n",string);  +printf"2.buf1=%s\n\n", BUF1);  -     /*  the * * Results of execution: * **2.buf1=12345 $     */  Panax Notoginseng    -     /*3. String to be taken to the specified character*/   the     string="123/456";  +sscanfstring,"%[^/]", BUF1);  Aprintf"3.string=%s\n",string);  theprintf"3.buf1=%s\n\n", BUF1);  +     /*  - * * Results of execution: $ **3.buf1=123 $     */   -    -     /*4. String to be taken to the specified character set*/   the     string="123abcABC";  -sscanfstring,"%[^a-z]", BUF1); Wuyiprintf"4.string=%s\n",string);  theprintf"4.buf1=%s\n\n", BUF1);  -     /*  Wu * * Results of execution: - **4.BUF1=123ABC About     */   $    -     /*5. Take a string containing only the specified character set*/   -     string="0123abcABC";  -sscanfstring,"%[0-9]%[a-z]%[a-z]", Buf1, Buf2, BUF3);  Aprintf"5.string=%s\n",string);  +printf"5.buf1=%s, buf2=%s, buf3=%s\n\n", Buf1, Buf2, BUF3);  the     /*  - * * Results of execution: $ **5.buf1=123, BUF2=ABC, Buf3=abc the     */   the    the     /*6. Get the string in the middle of the specified character*/   the     string="ios<android>wp7";  -sscanfstring,"%*[^<]<%[^>]", BUF1);  inprintf"6.string=%s\n",string);  theprintf"6.buf1=%s\n\n", BUF1);  the     /*  About * * Results of execution: the **6.buf1=android the     */   the    +     /*7. Specify the string to skip*/   -     string="iosvsandroid";  thesscanfstring,"%[a-z]vs%[a-z]", BUF1, BUF2); Bayiprintf"7.string=%s\n",string);  theprintf"7.buf1=%s, buf2=%s\n\n", BUF1, BUF2);  the     /*  - * * Results of execution: - **7.buf1=ios, Buf2=android the     */   the    the     /*8. Splitting a string separated by a character*/   the     string="android-iphone-wp7";  -     /*  the * * String by '-' so far, followed by the delimiter '-', the * * Filter action, a bit similar to the 7th the     */  94sscanfstring,"%[^-]-%[^-]-%[^-]", Buf1, Buf2, BUF3);  theprintf"8.string=%s\n",string);  theprintf"8.buf1=%s, buf2=%s, buf3=%s\n\n", Buf1, Buf2, BUF3);  the     /* 98 * * Results of execution: About **8.buf1=android, Buf2=iphone, buf3=wp7 -     */  101   102     /*9. Extract your email address*/  103     string="Email:[email protected]"; 104sscanfstring,"%[^:]:%[^@]@%[^.]. %s", Buf1, Buf2, BUF3, BUF4);  theprintf"9.string=%s\n",string); 106printf"9.buf1=%s, buf2=%s, buf3=%s, buf4=%s\n\n", Buf1, Buf2, BUF3, BUF4); 107     /* 108 * * Results of execution:109 **9.buf1=email, buf2=beijing, Buf3=sina, buf4=com.cn the     */  111    the     /*10. Filter out strings that you don't want to intercept or do not need--add,113 * * After the% number plus a * number, which means to filter the string, do not read the     */   the     string="android iphone wp7";  thesscanfstring,"%s%*s%s", BUF1, BUF2); 117printf"10.string=%s\n",string); 118printf"10.buf1=%s, buf2=%s\n\n", BUF1, BUF2); 119     /*  - * * Results of execution:121 **10.android wp7122     */  123 }  124    the intMainintargcChar**argv)126 {  127 sscanf_test ();  -       129     return 0;  the}

sprintf function is also very strong is to write the data into the string not much to repeat

Sstream is C + + only.

Flow processing is also very powerful

But since I'm not ready to continue learning C + +,

It's a waste of time to find work.

The next period of time mainly focus on the algorithm

Start learning Java and Python

SSCANF sprintf Sstream

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.