• sscanf输入总结


    2017-08-21 15:09:47

    writer:pprp

    sscanf很好用的,一般配合gets()来使用

    /*
    theme: usage of sscanf
    writer:pprp
    date:2017/8/21
    declare:sscanf的基本用法总结
    */
    
    #include <bits/stdc++.h>
    
    using namespace std;
    
    char s[] = "abcdefghijklmn";
    
    int main()
    {
          char str[10010];
          
          //s如果是string类型的就不行
          //用来取指定长度的字符串
          sscanf(s,"%5s", str);
          printf("%s
    ",str);
          
          //从a开始的之后的字符
          sscanf(s,"a%s", str);
          printf("%s
    ", str);
          
          // 取到指定字符为止的字符串。如在下例中,取遇到空格为止字符串。
          sscanf("123456 78910","%[^ ]",str);
          printf("%s
    ",str);
          
          //取仅包含指定字符集的字符串。如在下例中,取仅包含1到9和小写字母的字符串。
          sscanf("123445KUTYFHGasd788765asdffdsafdsIUYFF1234SRF","%[1-9a-z]",str);
          printf("%s
    ",str);
          
          //取到指定字符集为止的字符串。如在下例中,取遇到大写字母为止的字符串。
          sscanf("12344321asdffdaASDFFDSA","%[^A-Z]",str);
          printf("%s
    ",str);
          
          //给定一个字符串iios/12DDWDFF@122,获取 / 和 @ 之间的字符串,先将 "iios/"过滤掉,再将非'@'的一串内容送到buf中
          //*代表跳过此数据不读入. (也就是不把此数据读入参数中)
          sscanf("iios/12DDWDFF@122","%*[^/]/%[^@]",str);
          printf("%s
    ", str);
          
          //给定一个字符串““hello, world”,仅保留world。(注意:“,”之后有一空格)
          //第一个被读入的串被过滤掉了
          sscanf("hello world","%*s%s",str);
          printf("%s
    ",str);
          
          
          return 0;
    }

     

  • 相关阅读:
    【转】Exchange Server 的防火墙开放端口
    【转】AD常用端口
    centos6安装python3
    CMD下的netstat命令
    CMD定时倒数
    【转】netstat 的10个基本用法
    不联网如何PING通WIN主机和VMWARE(懵懂版,不含原理)
    【转载】Putty出现 Network error:Software caused connection abort
    MFC Unicode 字符集下格式转换
    MFC嵌套OpenCV窗口并显示图片
  • 原文地址:https://www.cnblogs.com/pprp/p/7404542.html
Copyright © 2020-2023  润新知