Updates from December, 2011 Toggle Comment Threads | Keyboard Shortcuts

  • admin 12:35 am on December 5, 2011 Permalink | Reply
    Tags: c struct   

    C struct initialize 

    struct SMyOrder
    {
    int quantity;
    int price;
    };

    int main()
    {
    static const struct SMyOrder zero_a;
    struct SMyOrder a = zero_a;

    printf(“price=%d, quantity=%d \n”, a.price, a.quantity);

    return 0;
    }

     
  • admin 11:27 pm on December 1, 2011 Permalink | Reply
    Tags: linux c   

    发个带颜色的printf:
    enum zh_color_set {
    COLOR_BLACK = 30,
    COLOR_RED,
    COLOR_GREEN,
    COLOR_YELLOW,
    COLOR_BLUE,
    COLOR_MAGENTA,
    COLOR_CYAN,
    COLOR_WHITE
    };
    void zh_printf(int color, char *fmt, …)
    {
    va_list ap;
    printf(“%c[1;%d;40m”, 0x1B, color);

    va_start(ap, fmt);
    vprintf(fmt, ap);
    va_end(ap);

    printf(“%c[0m”, 0x1B);
    }

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel