1
當我使用printf打印時,獲得了不同的值。我嘗試了很多來解決這個問題。但我沒有得到如何解決這個 - 這裏是代碼 -C中的值覆蓋
#Dymically allocated memory-
char **child = (char **)malloc(totalRows * sizeof(*child));
int i=0;
while ((row = mysql_fetch_row(res)) != NULL)
{
child[i] = (char *)malloc(strlen(row[1]) + 1);
child[i]=strdup(row[1]);
printf("%u %s \n", &child[i], child[i]);
i++;
}
int j=0;
for (j; j<i; j++)
printf("%u %s \n", &child[j], child[j]);
輸出的幾行被
7127200 1111
7127208 111111vv
7127216 111111sd
7127224 111111en
7127232 111113nk
7127240 111113t3
7127200 1111
7127208 1111 //..Here I am getting different value-
7127216 111111sd
7127224 111111en
7127232 111113nk
7127240 111113t3
爲什麼你叫分配malloc'的'的返回值,然後'strdup'相同的變量? ['strdup'](http://linux.die.net/man/3/strdup)在內部調用'malloc'。 –
那麼,確切地說應該是什麼代碼?其實我試過一切來解決這個 – user23750
打印存儲在'child [i/j]'中的地址不是更有用嗎?然後你可以區分指針變化和指向變化的事物。 – Tommy