zoukankan      html  css  js  c++  java
  • printf

    碰到了printf的一个很奇葩的用法。

    A width or precision may be specified as *, in which case the value is compputed by converting the next argument (which must be an int). For example, to print at most max characters from a string s.

    #include <stdio.h>  
    #include <cstring.h>  
    
    int main() {  
        int max;  
        char *s = "this is a test!
    ";  
    
        scanf("%d", &max);  
        printf("%.*s
    
    ", max, s);  
    
        return 0;  
    }
    

    提示:自己手动输入值,试试

    再来一个例子

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    int main() {
        int max, d;
    
        scanf("%d%d", &d, &max);
        printf("%0*d
    ", max, d);
    
        return 0;
    }
    

    input

    3 5

    output

    00003

    这篇文章用markdown写的哦,感觉还不错

  • 相关阅读:
    HTML中Css补充资料
    HTML表单
    HTML盒子模型
    标准文档流
    什么使用面向对象
    static修饰
    static修饰
    列表样式
    java基础(9)
    java基础(8)
  • 原文地址:https://www.cnblogs.com/tanhehe/p/3250859.html
Copyright © 2011-2022 走看看