我在我的工程中需要使用一个全局字符指针变量,但是声明后在函数中进行对
此变量进行更改的时候总是出现错误。
char * myChar="This is my string data.";void myfunction()
{
...
myChar= "This is my new string."; // 程序执行到此出现错误;
...
}
此变量进行更改的时候总是出现错误。
char * myChar="This is my string data.";void myfunction()
{
...
myChar= "This is my new string."; // 程序执行到此出现错误;
...
}
char * myChar="This is my string data.";
更改为
char myChar[]="This is my string data.";
即可.但是你不得使用超过strlen("This is my string data.")长度.void myfunction()
{
...
myChar= "This is my new string."; // 程序执行到此出现错误;
...
}
需改为
void myfunction()
{
...
strcpy(myChar, "This is my new string.");
...
}标准方法:char* myChar=NULL;void main()
{
myChar=new char[1024];
if(!myChar)
return; strcpy(myChar,"This is my string data."); .... delete []myChar;
}void myfunction()
{
...
strcpy(myChar, "This is my new string.");
...
}
但是在我的DLL中还是会出错。
在EXE工程中使用没有错误,
怎么回事?