How to convert unsigned long to string

后端 未结 6 1924
[愿得一人]
[愿得一人] 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:26

    For a long value you need to add the length info 'l' and 'u' for unsigned decimal integer,

    as a reference of available options see sprintf

    #include 
    
        int main ()
        {
          unsigned long lval = 123;
          char buffer [50];
          sprintf (buffer, "%lu" , lval );
         }
    

提交回复
热议问题