Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/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 使用未声明的标识符';a';_C - Fatal编程技术网

C 使用未声明的标识符';a';

C 使用未声明的标识符';a';,c,C,我正试图编写一个C程序,但编译器不断报告错误,它无法理解标识符“a”。有人能告诉我这里出了什么问题吗? 以下是代码和错误: #include <string.h> #include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <sys/types.h> int main() { char buffer[200]; memset(buffer,’a’,2

我正试图编写一个C程序,但编译器不断报告错误,它无法理解标识符“a”。有人能告诉我这里出了什么问题吗? 以下是代码和错误:

#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>

int main() {
   char buffer[200];
   memset(buffer,’a’,200);
   int fd = open("test.txt", O_CREAT | O_RDWR );
   write(fd, buffer, 200);
   lseek(fd, 0, SEEK_SET);
   read(fd, buffer, 100);
   lseek(fd, 500, SEEK_CUR);
   write(fd, buffer, 100);
}

/Users/messfish/Desktop/os1.c:9:18: error: non-ASCII characters are not allowed
outside of literals and identifiers
   memset(buffer,’a’,200);
                 ^
/Users/messfish/Desktop/os1.c:9:22: error: non-ASCII characters are not allowed
  outside of literals and identifiers
   memset(buffer,’a’,200);
                   ^
/Users/messfish/Desktop/os1.c:9:21: error: use of undeclared identifier 'a'
   memset(buffer,’a’,200);
#包括
#包括
#包括
#包括
#包括
int main(){
字符缓冲区[200];
memset(缓冲区,'a',200);
int fd=open(“test.txt”,O|u CREAT | O|u RDWR);
写入(fd,缓冲器,200);
lseek(fd,0,SEEK_集);
读取(fd,缓冲器,100);
lseek(fd,500,SEEK_CUR);
写入(fd,缓冲器,100);
}
/Users/messfish/Desktop/os1.c:9:18:错误:不允许使用非ASCII字符
在文本和标识符之外
memset(缓冲区,'a',200);
^
/Users/messfish/Desktop/os1.c:9:22:错误:不允许使用非ASCII字符
在文本和标识符之外
memset(缓冲区,'a',200);
^
/Users/messfish/Desktop/os1.c:9:21:错误:使用未声明的标识符“a”
memset(缓冲区,'a',200);

我使用gcc作为编译器。

您使用了错误的引号类型,可能是因为您从某处复制粘贴了它。而不是

’a’
你想要

'a'

您在
a
周围使用了错误的单引号。您应该键入
'a'
,而不是复制/粘贴它。您最好检查返回值是否有错误,尤其是从
打开
读取
写入
中。