S
sugaray
The purpose of the following program is to store all the
arguments passed to main() into an array of char, and print'em out
onto the screen.
#include <stdio.h>
int main (int argc, char **argv)
{
int i;
char buffer[1024];
char *pb = buffer;
if (argc == 1)
exit (1);
for (i = 1; i < argc; ++i)
{
while (*argv != '\0')
*pb++ = *argv++;
*pb++ = ' ';
}
*pb = '\0';
printf ("%s\n", buffer);
return 0;
}
but when I tried to modify the string manipulation process
only using pointer arithmetic as below, I got stucked and
can't figure out why. probably I'm still got hazy about the
concept of pointer. hope you can help me out, thanx.
for(;argc>1;--argc)
{
while(*++*argv != '\0')
*pb++ = **argv++;
*pb++ = ' ';
}
arguments passed to main() into an array of char, and print'em out
onto the screen.
#include <stdio.h>
int main (int argc, char **argv)
{
int i;
char buffer[1024];
char *pb = buffer;
if (argc == 1)
exit (1);
for (i = 1; i < argc; ++i)
{
while (*argv != '\0')
*pb++ = *argv++;
*pb++ = ' ';
}
*pb = '\0';
printf ("%s\n", buffer);
return 0;
}
but when I tried to modify the string manipulation process
only using pointer arithmetic as below, I got stucked and
can't figure out why. probably I'm still got hazy about the
concept of pointer. hope you can help me out, thanx.
for(;argc>1;--argc)
{
while(*++*argv != '\0')
*pb++ = **argv++;
*pb++ = ' ';
}