目前,我在realloc數組字符串中存在一些混淆。如果我有這樣的:realloc字符串數組
char** str = (char**)malloc(100*sizeof(char*));
str[0] = (char*)malloc(sizeof(char)*7); //allocate a space for string size 7
//some other code that make the array full
我的問題是,如果我想的realloc str[0]
大小8
,我需要的realloc都str
和str[0]
這樣的:
str = (char**)realloc(str,sizeof(char*)*101);
str[0] = (char*)realloc(str[0],sizeof(char)*8);
這是正確的嗎?
好的。 thx人。我知道了 :) – 2013-03-20 00:48:54