[英]non-ASCII characters are not allowed outside of literals and identifiers (C programming)
好的,所以我正在为课堂编写代码,我认为一切都是正确的,除了我在 printf 语句中遇到错误我不知道如何编写 c 代码,我的老师让我们自学。 我在 printf 语句中收到未声明的标识符错误以及非 ASCII 字符错误,有人能帮我弄清楚为什么我会收到这些错误吗? 我只是想让他们逐字逐句打印出那个陈述,为什么它试图将其解读为不同的东西?
#include <inttypes.h>
#include <stdio.h>
typedef enum{false, true} bool;
bool is_little_endian()
{
int x = 1;
char *y = (char*)&x;
return 1;
}
unsigned int merge_bytes( unsigned int x, unsigned int y )
{
return (y & 0xffffff00) | (x & 0xff);
}
unsigned int replace_byte (unsigned int x, int i, unsigned char b)
{
int shift = (b << (8 * i));
int mask = 0xff << shift;
return (~mask & x) | shift;
}
int main()
{
if( is_little_endian() )
{
printf(“Your machine is a Little Endian machine\n”);
}
int x = 0x89ABCDEF;
int y = 0x76543210;
printf(“Merged number = 0x%x\n”, merge_bytes(x,y));
unsigned char z= 0x22;
printf(“Replaced number = 0x%x\n”, replace_byte(x,3,z));
return 0;
}
这是我得到的错误
HW3.c:30:8: error: non-ASCII characters are not allowed outside of literals and
identifiers
printf(“Your machine is a Little Endian machine\n”);
^
HW3.c:30:11: error: use of undeclared identifier 'Your'
printf(“Your machine is a Little Endian machine\n”);
^
HW3.c:30:52: error: non-ASCII characters are not allowed outside of literals and
identifiers
printf(“Your machine is a Little Endian machine\n”);
^
HW3.c:35:8: error: non-ASCII characters are not allowed outside of literals and
identifiers
printf(“Merged number = 0x%x\n”, merge_bytes(x,y));
^
HW3.c:35:11: error: use of undeclared identifier 'Merged'
printf(“Merged number = 0x%x\n”, merge_bytes(x,y));
^
HW3.c:35:33: error: non-ASCII characters are not allowed outside of literals and
identifiers
printf(“Merged number = 0x%x\n”, merge_bytes(x,y));
^
HW3.c:37:8: error: non-ASCII characters are not allowed outside of literals and
identifiers
printf(“Replaced number = 0x%x\n”, replace_byte(x,3,z));
^
HW3.c:37:11: error: use of undeclared identifier 'Replaced'
printf(“Replaced number = 0x%x\n”, replace_byte(x,3,z));
^
HW3.c:37:35: error: non-ASCII characters are not allowed outside of literals and
identifiers
printf(“Replaced number = 0x%x\n”, replace_byte(x,3,z));
^
9 errors generated.
看(“Your machine is a Little Endian machine\\n”);
. 注意“曲线引号”:这些显然不是 ASCII 引号(看起来像这样: "
)。您必须用“直引号”替换它们。(这也适用于所有其他字符串)。
不要在任何不是合适的文本编辑器的地方编辑代码。 特别是,不要在 MS Word、WordPad 或富文本编辑器中编辑代码,因为您可能会遇到类似这样的有趣问题。
如果您进行复制和粘贴,则可能会遇到这些问题。 答案是删除所有 @、" 等符号并使用键盘重做它们。希望这会有所帮助。
关键是您使用的是 MS Word 文本符号,而这些在 c 或其他编程语言中是不允许的,您知道 C 区分大小写。例如,当您阅读有关 c 编程的 pdf 文档时,您会复制一些源代码和您将它们粘贴到文本编辑器或编译器中,您通常会遇到这些类型的错误。
例如:char s3 [100] = {'a','b','\\0','d'}; //正确的
char s3 [] = {'S','t','u','d','i','\\0','e','r','e','r'};//不允许
所以最好重写代码而不是复制它们并粘贴到编辑器中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.