I do not understand why excessive white space is being written to stdout when I run this program.
int main(int argc, char **argv)
{
argv++;
for (int i = 0; i < argc - 1; i++)
{
for (int j = 0; j < strlen(*argv); j++)
{
putchar(*(*(argv + i) + j));
}
printf("\n");
}
}
Output:
(base) benjamin@benjamin-G5-5587:~$ ./uecho hello world baby yoyoyo
hello
world
baby
//whitespace?
yoyoy
Your inner loop condition is wrong, causing you to read out of bounds. It's always limited by
strlen(*argv), the first argument (thanks to the earlierargv++), even when processing the second and subsequent arguments. Since you read out to the length of"hello", you overread"baby", and fail to read all of"yoyoyo". Overreadingbabyby one character ends up writing aNULtostdout, which I'm guessing your terminal is interpreting in a manner similar to a newline.I'd suggest:
End result would look like: