zoukankan      html  css  js  c++  java
  • sscanf的最基础用法(非原创)

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<string.h>
     4 
     5 int main(){
     6     char str[100];
     7     //用法一:取指定长度的字符串
     8     sscanf("12345","%4s",str);
     9     printf("用法一
    str = %s
    ",str);
    10 
    11     //用法二:格式化时间
    12     int year,month,day,hour,minute,second;
    13     sscanf("2013/02/13 14:55:34","%d/%d/%d %d:%d:%d",&year,&month,&day,&hour,&minute,&second);
    14     printf("用法二
    time = %d-%d-%d %d:%d:%d
    ",year,month,day,hour,minute,second);
    15 
    16     //用法三:读入字符串
    17     sscanf("12345","%s",str);
    18     printf("用法三
    str = %s
    ",str);
    19 
    20     //用法四:%*d 和 %*s 加了星号 (*) 表示跳过此数据不读入. (也就是不把此数据读入参数中)
    21     sscanf("12345acc","%*d%s",str);
    22     printf("用法四
    str = %s
    ",str);
    23 
    24     //用法五:取到指定字符为止的字符串。如在下例中,取遇到'+'为止字符串。
    25     sscanf("12345+acc","%[^+]",str);
    26     printf("用法五
    str = %s
    ",str);
    27 
    28     //用法六:取到指定字符集为止的字符串。如在下例中,取遇到小写字母为止的字符串。
    29     sscanf("12345+acc121","%[^a-z]",str);
    30     printf("用法六
    str = %s
    ",str);
    31     return 0;
    32 }

    本文转自:http://blog.csdn.net/sjf0115/article/details/8579935

  • 相关阅读:
    Java 中的按值传递
    字符串排序(非字典排序)
    字符串匹配的KMP算法(转)
    效率更高的整数转化为字符串函数
    Trie 树(转)
    C 语言字符串(译)
    linux 下 epoll 编程
    CSS攻击:记录用户密码
    Wireshark(抓包神器)使用方法
    搭建KVM环境——Linux上安装KVM带web管理界面
  • 原文地址:https://www.cnblogs.com/zmin/p/7620460.html
Copyright © 2011-2022 走看看