簡體   English   中英

C-如何在數組中存儲帶有變量的字符串?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM