How to convert unsigned long to string

后端 未结 6 1918
[愿得一人]
[愿得一人] 2020-12-08 03:14

In the C language, how do I convert unsigned long value to a string (char *) and keep my source code portable or just recompile it to work

6条回答
  •  清歌不尽
    2020-12-08 03:29

    const int n = snprintf(NULL, 0, "%lu", ulong_value);
    assert(n > 0);
    char buf[n+1];
    int c = snprintf(buf, n+1, "%lu", ulong_value);
    assert(buf[n] == '\0');
    assert(c == n);
    

提交回复
热议问题