I am playing with some C programming and I wrote this simple program to print the arguments that were fed to the program.
My question is that if I use the line pi++ shouldn't pi now point to the next char in the array? When I tried this it didn't work. I found that instead I had to increment pi twice for it to accurately put out the arguments as they were fed in.Code:#include <stdio.h> int main(int argc, char * argv[]){ char *pi; int i; pi = argv[1]; printf("%d args.\n",argc-1); printf("input: "); for(i=0;i<argc-1;i++){ printf("%c, ",*pi); /*The line below increments pi by 1 char worth of bytes */ pi+=sizeof(pi)/2; /* An alternative to the above line is putting pi++ twice - why? */ } printf("\n"); return 0; }




Reply With Quote
