在C語言中,可以使用數組和指針來創建字符串數組列表。下面是一個簡單的示例:
#include <stdio.h>
#include <string.h>
int main() {
char *strList[] = {"apple", "banana", "cherry", "date"};
int size = sizeof(strList) / sizeof(strList[0]);
for (int i = 0; i < size; i++) {
printf("%s\n", strList[i]);
}
return 0;
}
在上面的示例中,我們定義了一個名為strList的字符串數組列表,其中包含了四個字符串。我們使用sizeof運算符來計算字符串數組列表的大小,然后使用循環遍歷并打印出每個字符串。
如果需要動態地添加或刪除字符串,可以使用動態內存分配函數malloc和free,或者使用strcpy和strcat函數來處理字符串的操作。