How to convert an int to string in C?

后端 未结 10 1917
南方客
南方客 2020-11-22 02:51

How do you convert an int (integer) to a string? I\'m trying to make a function that converts the data of a struct into a string to save it in a fi

10条回答
  •  有刺的猬
    2020-11-22 03:34

    This is old but here's another way.

    #include 
    
    #define atoa(x) #x
    
    int main(int argc, char *argv[])
    {
        char *string = atoa(1234567890);
        printf("%s\n", string);
        return 0;
    }
    

提交回复
热议问题