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

  • 相关阅读:
    Super Mario
    SPOJ Count on a tree
    SPOJ DQUERY
    51nod 区间中第K大的数
    POJ2104 K-th Number
    矩阵模板
    Sasha and Array
    MVC RenderSection
    Lazy Acquisition
    .net4.5 await async 简化之后的异步编程模型
  • 原文地址:https://www.cnblogs.com/zmin/p/7620460.html
Copyright © 2011-2022 走看看