I've to read a table from a txt file and I've to write values into memory.
I'm able to read data (row by row) from file and to put them into variables (using sscanf), but I don't know how to create and fill an array of "strings".
I need to create an array of n rows and 9 cols of strings/chars.
This code gives me a compiler warning ("warning: passing argument 1 of 'strcpy' makes pointer from integer without a cast") and the program error:
char matrix_model_data[3][10];
strcpy(matrix_model_data[0][0],"some text");
printf("VALUE = %s\n",matrix_model_data[0][0]);
How can I do?
Thanks
EDIT
Now I've modified the code using my values, but it prints only the last record 1317 times (mdata_num = 1317)...why?
char ***table = (char ***) calloc(mdata_num, sizeof(char**));
int i, j, m;
for(i=0; i<mdata_num; i++)
{
fgets(LineIn,500,fIn);
sscanf(LineIn, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",stTemp0,stTemp1,stTemp2,stTemp3,stTemp4,stTemp5,stTemp6,stTemp7,stTemp8);
iterazioni++;
table[i] = calloc(COLUMNS, sizeof(char*));
for(j=0; j<COLUMNS; j++)
{
table[i][j] = calloc(MAX_STRING_SIZE, sizeof(char));
}
table[i][0] = stTemp0;
table[i][1] = stTemp1;
table[i][2] = stTemp2;
table[i][3] = stTemp3;
table[i][4] = stTemp4;
table[i][5] = stTemp5;
table[i][6] = stTemp6;
table[i][7] = stTemp7;
table[i][8] = stTemp8;
}
for(i=0; i<mdata_num; i++)
{
for(j=0; j<COLUMNS; j++)
{
printf("%s\t", table[i][j]);
}
printf("\n");
}
//FREE THE TABLE
for(i=0; i<mdata_num; i++)
{
for(j=0; j<COLUMNS; j++)
{
free(table[i][j]);
}
free(table[i]);
}
free(table);