我是一個小菜,所以不要難過。如何在C中動態分配一個字符串數組?
而不是像這樣;
char string[NUM OF STRINGS][NUM OF LETTERS];
是否可以動態分配多少字符串會使用malloc數組中就好像當你動態地字符指針分配內存?這樣的事情:
int lines;
scanf("%d", &lines);
char *string[NUM OF LETTERS]
string = malloc(sizeof(char) * lines);
我試過了,但它不起作用;必須有一些我做錯了。 我想到了其他的解決辦法是:
int lines;
scanf("%d", &lines);
char string[lines][NUM OF LETTERS];
,但我想知道這是否使用malloc是可能的。
這可以幫助嗎? http://stackoverflow.com/a/25755572/1392132 – 5gon12eder