Shadi Shadi - 8 months ago 36
C Question

changing command line arguments

I am writing a C program. It takes its arguments from commandLine. I want to change the commandLine arguments in the code. As they are defined as "const char *", I can not change them using "strcpy", "memcpy", ... Also, you know, I can not just change their type from "const char *" to "char *".
Is there any way to change them?

Thank you so much in advance.

Best regards,


According to C99 ยง5., the signature for main is

int main(int argc, char *argv[]) { /* ... */ }

So you are allowed to remove the const. Just don't cause a buffer overrun by strcpying in longer strings than the original arguments, or attempting to install more arguments than originally passed.

Everyone else is basically right that you should create a copy instead.