I've been trying to solve the "MIME type" puzzle from this site: https://www.codingame.com/games/puzzles/
And I've found an answer to this puzzle on the following site: http://ethiery.vvv.enseirb-matmeca.fr/CGsolo/mime-type.html
- Can somebody explain what the
p = d.elmts+i;
(line 49) from the above link does? - Why doesn't it work when I omit the 49th line and use this code in the subsequent lines instead? (It does not show an error till I try to print the ext and mimes using the d.elmts[i].ext/mime). It works like a charm when I use the
p = d.elmts+i;
. (First time on stackoverflow. I'm not sure if this'll appear as a code snippet. Apologies if it doesn't)
Code
d.elmts[i].ext = malloc(11*sizeof(char));
d.elmts[i].mime = malloc(51*sizeof(char));
scanf("%s %s\n",d.elmts[i].ext, d.elmts[i].mime);