我有至多20長度的10個字符串數組,我建立如何將char [n] [length + 1]轉換爲C中的常量字符串數組?
char buffer[10][20] = {0};
//populate the buffer with 10 strings
//after this point, no more changes to the buffer allowed
//make a new pointer to indicate that I want the buffer finalized
const char **finalized = buffer;
但以前的失敗,並警告
warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
做有一個字符串的工作
類似的東西char buffer[20] = {0};
//populate the buffer
const char *finalized = buffer;
在第一種情況下施放的正確方法是什麼?
'{0}'是* *一個維陣列的初始值設定。 –
@ Eugene Sh .:沒有。而且,這是荒謬的。在C語言中,'{0}'是一個慣用的通用零初始化器。它可以用來絕對*初始化*任何*。 – AnT
是的,但並非沒有抱怨,例如'警告:初始化程序周圍缺少大括號[-Wmissing-braces]'。 (作爲'-Wall'的一部分啓用) –