0

I want to modify an old C code, that takes inputs from the commandline to take a constant argv-vector of strings, defined from inside main.

I get a run-time exception

//void main(ac,av)
//char *av[]; 
void main()
{
    char *av[]= {"C:\\spice3f5.exe","input.cir","-r","output.txt",0};
    char  **tv;
    tv = av;
    tv++;
    **tv='-';// "Access violation writing location 0x00708edc."
    (*tv)[0] = '-';//Same runtime exception
}

This simply shouldn't happen...Is it a bug in Visual C++ 2010?

4

1 回答 1

9

的元素av是指向字符串常量的指针。因此,修改它们会导致访问冲突。这不是 Visual C++ 的错误。

于 2012-07-18T16:11:37.383 回答