【发布时间】:2015-05-21 09:11:17
【问题描述】:
我正在尝试在德州仪器 CCS 中创建这样的 C 字符串:{steps: nSteps} 以便将其作为 json 发送,nSteps 是 int。我也想转换为字符串使用以下代码:
void jsonSteps(char* stepstr, int steps)
{
char x[3];
const char s1[10], s3[10];
char s2[10];
itoa(steps,x,10);
s1[]="{steps:";
s3[]="}";
s2 = strcat(s1, x);
stepstr = strcat(s2, s3);
}
我有这个错误
s1[]="{steps:";
和
s3[]="}";
我收到一个错误
"#29 期望一个表达式"
还有
" #169-D "const char *" 类型的参数与 "
类型的参数不兼容
【问题讨论】:
-
这看起来不像 C 代码。你不能只是编造一些东西并期望它们起作用。
-
当然可以
atoi...atoi...atoi...itoa...BINGO! -
你在看哪本书?你的书对
sprintf有什么看法?
标签: c arrays string strcat itoa