Your definition of argv
is wrong. From the C11 standard §5.1.2.2.1/2::
The parameters argc and argv and the strings pointed to by the argv
array shall be modi?able by the program, and retain their last-stored
values between program startup and program termination.
It should be char **argv
or char *argv[]
int main(int argc, char *argv[])
{
int count = argc;
char **savedArgv = argv;
while (count--)
{
printf("%s%s", *argv++, (count > 0) ? " " : "");
}
printf("
");
count = argc;
argv = savedArgv;
while (count--)
{
// how to reset argv to point to argv[0] before calling *argv++
printf((count > 0) ? "%s " : "%s", *argv++);
}
printf("
");
return 0;
}
https://godbolt.org/z/Me4Pq8
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…