I am trying to insert value in to each element of array dynamically but couldn't make it work.
char itemCodeToSend[100];
So i used 'strcpy`
char itemCode[100] = "F,T,H";// So on
char * p = strtok (itemCode, ","); // Parsing using comma
int n_spaces = 0, i;
int position = 0;
while (p) {
strcpy(&itemCodeToSend[position],p);
printf("<p>%i %s",position,&itemCodeToSend[position]);
position++;
p = strtok (NULL, ",");
}
// Trying to print the array
i=0;
for (i; i < 34; i++){
printf ("res[%d] = %s\n", i, &itemCodeToSend[i]);
}
While printing what i am expecting is
itemCodeToSend[0] = "F";
itemCodeToSend[1] = "T";
itemCodeToSend[2] = "H";
But What i am getting is
itemCodeToSend[0] = "FTH";
itemCodeToSend[1] = "TH";
itemCodeToSend[2] = "H";
Not sure how to handle this.