sprintf() without trailing null space in C

后端 未结 8 1291
鱼传尺愫
鱼传尺愫 2021-02-01 13:37

Is there a way to use the C sprintf() function without it adding a \'\\0\' character at the end of its output? I need to write formatted text in the middle of a fixed width stri

8条回答
  •  后悔当初
    2021-02-01 14:11

    Actually this example will not add a null if you use snprintf:

    char name[9] = "QQ40dude";  
    unsigned int i0To100 = 63;  
    _snprintf(&name[2],2,"%d",i0To100);  
    printf(name);// output will be: QQ63dude  
    

提交回复
热议问题