Hi ,
Please I need help to trace this program:
Show the output for the following program
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("%.6s\n", tricky);
tricky = show(tricky);
printf("%.6s\n", tricky);
}
char * show(char *s) {
char *keep = s + 4;
printf("%c %.8s\n", *keep, s+2);
strncpy(++keep, s, 10);
return keep-3;
}
Output (Exactly as it would appear)
Line 1 p _ i p p e r y _ W _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Line 2 i p p S l i _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Line 3 l _ p S l i p p S l _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Line 4 p S l i p p _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
I get the first line( the print inside the function)
But I dont get the second line.
My problem is the command"strncpy(++keep, s, 10);"
Since I have problem with that , I cannot continue tracing the program. Can someone help me please to get Line 2?
thank you for your help
B.