zoukankan      html  css  js  c++  java
  • sscanf、strsep

    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
        char token[] ="abdzxbcdefgh";
        char str[]="3:2:09";
        int a1=0, a2=0, a3=0;
        int ret;
    
        printf("%s
    ",token);
        char *tokenremain = token;
        char *tok1 = strsep(&tokenremain,"cde");
        printf("tok1:%s,token:%s
    ",tok1,tokenremain);
        tok1 = strsep(&tokenremain,"cde");                                           
        printf("tok1:%s,token:%s
    ",tok1,tokenremain);
        printf("%s
    ", token );
        ret=sscanf( str, "%d:%d:%d", &a1, &a2, &a3 );
        printf( "ret=%d,%d:%d:%d
    ", ret, a1, a2, a3 );
    
        return 0;
    }

    输出:

    abdzxbcdefgh
    tok1:ab,token:zxbcdefgh
    tok1:zxb,token:defgh
    ab
    ret=3,3:2:9

    注意问题:

    1、sscanf返回值,是识别token的个数;

    2、strsep会修改被扫描的字符串,会在扫描到的地方设置为''

  • 相关阅读:
    codeforces 1096 题解
    pkuwc 前的任务计划
    codeforces 1093 题解
    luoguP5068 [Ynoi2015]我回来了
    luoguP5074 Eat the Trees
    二分
    保护
    数数字
    旅行
    すすめ!
  • 原文地址:https://www.cnblogs.com/feika/p/4025658.html
Copyright © 2011-2022 走看看