Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 未声明的标识符(尽管已声明)_C_Identifier_C89 - Fatal编程技术网

C 未声明的标识符(尽管已声明)

C 未声明的标识符(尽管已声明),c,identifier,c89,C,Identifier,C89,对于一个我尝试创建一个文件并随后写入其中的程序,我编写了以下内容: int main(){ ... .... (some code) .... char DataBuffer[] = "This is the test file"; ... ... } DWORD dwCreationDisposition = CREATE_NEW; 我得到错误“DataBuffer

对于一个我尝试创建一个文件并随后写入其中的程序,我编写了以下内容:

 int main(){
        ...
        ....
       (some code)
        ....
          char DataBuffer[] = "This is the test file";
        ...
        ...


}
   DWORD dwCreationDisposition = CREATE_NEW;
我得到错误“DataBuffer:undeclared identifier”。 我使用微软Visual C++快件。在StasOffFuff.com中的一个老问题中,我已经阅读到VisualC++使用了旧的C89标准,它不支持C99标准。 出于这个原因,我必须在开始时声明变量(我对CreateFile()和WriteFile的其余参数进行了声明)。我的意思是,当你考虑以下内容:

 int main(){
        ...
        ....
       (some code)
        ....
          char DataBuffer[] = "This is the test file";
        ...
        ...


}
   DWORD dwCreationDisposition = CREATE_NEW;
然后我将其拆分并更改为:

   DWORD dwCreationDisposition;
   ...
   dwCreationDisposition = CREATE_NEW
但是我不知道我应该如何使用数组。例如,当我写:

 char DataBuffer[];
 ....
 DataBuffer[] = = "This is the test file";
然后我也得到了同样的错误消息。 我能做什么?是否有可能更改编译器选项?还是有机会重写它,使集成编译器接受它作为其他拆分的变量/参数


致以最诚挚的问候,

如果您希望您的字符串可重写,您应该这样做:

 char DataBuffer[MAX_SIZE];
 ....
 strcpy(DataBuffer,"This is the test file");

也考虑使用<代码> STRNCPY 避免缓冲区溢出错误。

如果字符串为常量,则:

const char DataBuffer[] = "This is the test file";

char*DataBuffer;/*…*/DataBuffer=“string”您应该仍然能够在一条语句中声明init变量,尽管是在作用域的开头。也就是说,您还可以使用
{}
打开一个新范围,以便在那里声明一个新变量。请注意,@Mint97的建议是不同的,因为它声明了一个指向非常量数据的指针,您仍然不能修改该指针,而原始代码声明了一个可变的字符数组。“未声明的标识符虽然已标识”是指“未声明的标识符尽管已声明?”哦,是的……我将更改它。谢谢xD