A funny thing with sprintf

后端 未结 6 2031
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 14:17

I\'m so confused with sprintf that a funny problem with different platfrom. Code :

int main () 
{
    char sql[1024];
    uint32_t app_id = 32;
    uint64_t          


        
6条回答
  •  孤城傲影
    2020-12-15 14:20

    As has been pointed out, the proper formatting specifier for uint64_t is PRIu64 (not lu, since there's no guarantee that uint64_t is long).

    So, you need to use that:

    #define __STDC_FORMAT_MACROS
    #include 
    
    char sql[1024];
    uint32_t app_id = 32;
    uint64_t task_id = 64;
    sprintf(sql, "%u, %" PRIu64, app_id, task_id);
    printf ("%s\n", sql);
    

提交回复
热议问题