解决方法
修改程序中argv的内容:
#include <stdio.h> #include <time.h> void delay (long int msecs) { clock_t delay = msecs * CLOCKS_PER_SEC / 1000; clock_t start = clock(); while (clock() - start < delay); } void main (int argc,char **argv) { if (argc == 2) { printf ("%s\n",argv[1]); delay (6000); argv[1][0] = 'x'; argv[1][1] = '.'; argv[1][2] = 'x'; printf ("%s\n",argv[1]); delay (5000); printf ("done\n"); } else printf ("argc != 1: %d\n",argc); }
调用:
./argumentClear foo foo x.x done
结果,按ps查看:
asux:~ > ps auxwww | grep argu stefan 13439 75.5 0.0 1620 352 pts/5 R+ 17:15 0:01 ./argumentClear foo stefan 13443 0.0 0.0 3332 796 pts/3 S+ 17:15 0:00 grep argu asux:~ > ps auxwww | grep argu stefan 13439 69.6 0.0 1620 352 pts/5 R+ 17:15 0:02 ./argumentClear x.x stefan 13446 0.0 0.0 3332 796 pts/3 S+ 17:15 0:00 grep argu