Hell I was wondering if somone could help me understand how this code returns the output that it does... it was a homework assignment of mine, i got it wrong and the teacher gave us solutions but even with the solutions i do not see how this code works
Code:
#include <stdio.h>
#include <string.h>
char * show(char *s);
void main() {
char signs[3][30] = {"Watch Your Step",
"Slippery When Wet",
"Danger - High Voltage"};
char *tricky;
tricky = show(signs[1]);
printf(%.6\n",tricky);
tricky = show(tricky);
printf("%.6\n",tricky); }
char * show(char *s) {
char *keep = s + 4;
printf("%c %.8s\n", *keep, s+2);
strncpy(++keep, s, 10);
return keep-3; }
and the output (solution) is:
(The underscores represent blanks)
Code:
Line 1: p_ippery_W
Line 2: ippsli
Line 3 l_pslippsl
Line 4: pslipp
any explanation of even a little piece of this is greatly appreciated, thank you