Dot operator for strings works in one case but not another

hist[counter].cmd

The source of your confusion seems to be that array subscripting does more than you think. Array subscripting contains an implicit dereference and is not simply shifting the hist pointer along to yield another pointer. hist[counter] is equivalent to (*(hist + counter)) by definition.

These are all equivalent and work:

/* 1 */ n->bfr = str;
/* 2 */ (*n).bfr = str;
/* 3 */ (*(n + 0)).bfr = str;
/* 4 */ n[0].bfr = str;

The equivalence between 1 and 2 is a matter of definition: That's how the -> operator is defined. The equivalence between 2 and 3 should be obvious. The equivalence between 3 and 4 is also a matter of definition, as mentioned above.

/r/C_Programming Thread