I have the following code which gets some char tokens with strtok and it keeps these tokens one by one in a table and finally print these tokens. My error is in TABLE line:
error: invalid conversion from 'char* to 'char''
Something I misunderstood about the pointers and characters and I do not know how to write the TABLE line ((which I want to have the following format)). I tried something like
table[i][5+(i/2)] = *ptr;
but I had segmentation fault.
i = 0;
int offset = 5;
char* ptr;
ptr = strtok(buff,"do something");
char table[1][10];
while (ptr != NULL)
{
if (i == 0)
strcat(machine, ptr);
if (i == 2)
strcat(number, ptr);
if (i == 4)
strcat(hr, ptr);
if (i == 6)
strcat(dw, ptr);
if (i == 8)
strcat(vcc, ptr);
ptr = strtok(NULL,"do something");
table[i][5+(i/2)] = ptr;
i++;
}
printf("Final: %s, %s, %s, %s, %s\n", machine, number, hr, dw, vcc);
table[i][5+(i/2)] = *ptr;
is correct. The segmentation fault is becausei
exceeds the table dimensions. – Maroun