2017-02-23 7 views
-2

このようなCプログラムを作成しようとしていますが、コンパイラは識別子 'a'を理解できないというエラーを報告し続けます。誰かがここで何がうまくいかないか教えてもらえますか?私はコンパイラとしてgccのを使用宣言されていない識別子 '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); 

: は、ここでは、コードおよびエラーです。

+0

をしたいです。あなたはそれをコピー/ペーストするのではなく、*** ''a'' ***とタイプするべきです。 – jww

+0

エラーの戻り値、特に 'open'、' read'、および 'write'をチェックするとうまくいくでしょう。 – donjuedo

答えて

1

誤ったタイプの引用符を使用しています。おそらく、別の場所からコピー貼り付けしている可能性があります。代わりに

’a’ 

のあなたは、あなたが `A`周りに間違った単一引用符を使用している

'a' 
関連する問題