[英]C - How do you store a string with variables in it within an array?
因为我知道
char array[STRING_ELEMENTS + 1][MAX_STRING_LENGTH + 1];
/*just for the first element*/
array[0] == ("this number: %d, and that number: %d\n", a, b);
可能让我看起来恶心。 我不知道该如何做。
您不能在C中分配这样的字符串,但是可以使用snprintf :
snprintf(array[0], MAX_STRING_LENGTH, "this number: %d, and that number: %d\n", a, b);
(不要忘记在程序顶部附近的某个地方#include <stdio.h>
。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.