如何 do/simulate 三元表达式中的空字符

How to do/simulate an empty char in a ternary expression

我正在尝试格式化这样的字符串:

printf("%d%c", buffer[i], i == num_ints-1? '': ',');

因此数字打印如下:

123,929,345

然而做''是无效的。是否可以模拟 'nothing-char' 或只是不在三元中做任何事情?

不能有空字符,但可以有空字符串。所以使用 %s.

printf("%d%s", buffer[i], i == num_ints-1? "": ",");

您应该还可以在此处使用空字符 '[=11=]'

printf("%d%c", buffer[i], i == num_ints-1? '[=10=]': ',');