Shadi Shadi - 1 year ago 95
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,

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download