I ran the following just for fun, but cannot account for the result. Assume ./test WTF?
was run at the command line, and the output produced was
WTF? 6 2
. Why is there such a vast discrepancy between the reported value of argc (2 - as expected) and strlen(*argv), which came up as 6. I know an array of strings isn't exactly what strlen is looking for, however, I thought the value it produced (if it produced anything) would be reasonably close to argc. Thoughts?
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(int argc, char**argv)
{
for (int i = 1; i < argc; i++)
{
for (int j = 0; j < strlen(argv[i]); j++)
{
printf("%c", argv[i][j]);
}
printf(" ");
}
printf("\t%lu\t%d", strlen(*argv), argc);
printf("\n");
}