How can you copy strings?

Running into a bit of difficulty making duplicates of strings that enter the program via the command line. Evidently char p[] = q[]; doesn't work, and I can't do this:

for( i=0 ; q [i]!= EOF ; i++ )
p [i]= q[i];

as the string I'm trying to duplicate comes from the command line, from argv[1], so I can't wedge the i in anywhere. Any ideas how I can get around this?

strcpy(p,q); would be the way I would go. But just to make a point...

#include <stdio.h>
main(argc,argv)
int argc;
char *argv[];
{
      int i,k;
      for(i=0; argv; i++) {
           printf("i= %d \n", i);
           for(k=0; argv[k]; k++)
                printf("   char = %c\n", argv[k]);
      }
      exit(0);
}

Now, I wouldn't write code like that in a real program. It is, however, legal c.

Nice, thanks... I fiddled with that and I seem to have a copy of the string. However I'm trying to append ".bat" onto the end of said string by means of strcat(), but it's giving me evil warnings and stackdumps when I try to compile / run it.

It allows me to strcat(argv[1], ".bat") but not, for some odd reason, strcat(*dup, ".bat"), where dup[] is a duplicate of argv[1].

Overwriting the arguments like you show in your first use of strcat is illegal too, even if the compiler doesn't catch and your cpu succeeds in running the resulting code.

Your second example of strcat is so bizarre that I'm not sure what to think. My best guess is that dup is an array of characters. If so, try strcat(dup, ".bat");