|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
String array?
Program are as follows :
# 10 TRAN_MAX
# 5 ONE_TRAN
Main ()
{
Char **tran_list;
Int Rifa
LEAVES OF 13 SPECIES OF LAURACEAE initialization string array */
Tran_list = (char *) malloc (TRAN_MAX);
For (i = 0 i "TRAN_MAX; i++)
{
Tran_list[i] = (char *) malloc (ONE_TRAN);
Strcpy (tran_list[i], "1234");
}
LEAVES OF 13 SPECIES OF LAURACEAE print string array */
For (i = 0 i "TRAN_MAX; i++)
{
Printf ( "%s\n tran_list[%d] =", i, tran_list[i]);
}
LEAVES OF 13 SPECIES OF LAURACEAE release */ String array space
For (i = 0 i "TRAN_MAX; i++)
{
Free (tran_list[i]);
}
Return (0);
}
Operation time and the results are as follows :
Tran_list[0] = 1234
Tran_list[1] = 1234
Tran_list[2] = 1234
Tran_list[3] = 1234
Tran_list[4] = 1234
Tran_list[5] = 1234
Tran_list[6] = 1234
Tran_list[7] = 1234
Tran_list[8] = 1234
Tran_list[9] = 1234
But TRAN_MAX # 20, the results have problems :
Tran_list[0] =
Tran_list[1] = $
Tran_list[2] = H
Tran_list[3] = l
Tran_list[4] = 1234
Tran_list[5] = 1234
Tran_list[6] = 1234
Tran_list[7] = 1234
Tran_list[8] = 1234
Tran_list[9] = 1234
Tran_list[10] = 1234
Tran_list[11] = 1234
Tran_list[12] = 1234
Tran_list[13] = 1234
Tran_list[14] = 1234
Tran_list[15] = 1234
Tran_list[16] = 1234
Tran_list[17] = 1234
Tran_list[18] = 1234
Tran_list[19] = 1234
Why in front of distortion?
Please expert guidance and be grateful! |
String array?
Put tran_list = (char *) malloc (TRAN_MAX); It's changed
Tran_list = (char *) malloc (TRAN_MAX*sizeof (char *));
That is, (char *) malloc (TRAN_MAX*4);
You have no room for enough Array Pointer |
String array?
Solve the problem, so thanks! |
| |