gpt4 book ai didi

c - 如何在c中使用int变量创建一个字符串变量

转载 作者:太空宇宙 更新时间:2023-11-04 03:32:00 25 4
gpt4 key购买 nike

我是 C 的新手。我想使用 3 个整数和“/”构造一个字符串。

例如。

int a=01;
int b=10;
int c=2012;

char date = "a/b/c";

你能帮忙告诉我正确的方法是什么吗?

提前致谢

最佳答案

您应该分配足够的缓冲区并使用sprintf()

int a=01; /* this is octal value */
int b=10;
int c=2012;

char date[40]; /* 32-bit long integer will be at most 11 digits including sign in decimal */
sprintf(date, "%d/%d/%d", a, b, c);

关于c - 如何在c中使用int变量创建一个字符串变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35643404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com