title: Unix execv call only occurring on first run
body: <p>I'm writing a C program that is supposed to take its command line arguments, print them, remove the two arguments on the end, and then repeat until no arguments remain. For example, calling</p>
  
  <pre><code>a.out alpha beta gamma delta epsilon zeta eta
  </code></pre>
  
  <p>should print the following:</p>
  
  <pre><code>alpha beta gamma delta epsilon zeta eta
  beta gamma delta epsilon zeta
  gamma delta epsilon
  delta
  </code></pre>
  
  <p>The code I've come up with looks like this:</p>
  
  <pre><code>int main(int argc, char **argv) {
     char **ptr;
  
     for (ptr = argv+1; *ptr; ptr++)
        printf("%s ", *ptr);
     printf("\n");
  
     if (argc &gt; 3) {
         *(ptr-1)=NULL;
         execv(*argv, argv+1);
     }
     printf("Done!");
  
     return 0;   
  }
  </code></pre>
  
  <p>This works fine for the first exec call, but no further execs result, and the output with the given example is</p>
  
  <pre><code>alpha beta gamma delta epsilon zeta eta
  beta gamma delta epsilon zeta
  Done!
  </code></pre>
  
  <p>And I cannot figure why. Can anyone see what I'm doing wrong? Thanks!</p>