snprintf使用注意-会自动加上‘\0’结尾

来源:互联网 发布:深圳奥芯软件 编辑:程序博客网 时间:2024/06/15 13:43

snprintf使用的时候会自动补上结尾,例如打印一个64位的地址:

char str[19] = {0};

snprintf(str, 19, "%018p", p);


/*************************************************************************> File Name: main.c> Author: > Mail: > Created Time: 2016年12月15日 星期四 10时21分37秒 ************************************************************************/#include<stdio.h>#include<stdint.h>int main() {    int a = 6;    int *p = &a;    char str[19];    printf("%d\n", (intptr_t)p);    printf("0x%018x\n", (intptr_t)p);    snprintf(str, 19, "%018p", p);    printf("%s\n", str);    return 0;} 


0 0
原创粉丝点击