不允许在文字和标识符(C 编程)之外使用非 ASCII 字符



好的,所以我正在为类编写代码,我认为一切都是正确的,除了我在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 machinen”);
}
int x = 0x89ABCDEF;
int y = 0x76543210;
printf(“Merged number = 0x%xn”, merge_bytes(x,y));
unsigned char z= 0x22;
printf(“Replaced number = 0x%xn”, 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 machinen”);
       ^
HW3.c:30:11: error: use of undeclared identifier 'Your'
printf(“Your machine is a Little Endian machinen”);
        ^
HW3.c:30:52: error: non-ASCII characters are not allowed outside of literals and
      identifiers
printf(“Your machine is a Little Endian machinen”);
                                                 ^
HW3.c:35:8: error: non-ASCII characters are not allowed outside of literals and
      identifiers
printf(“Merged number = 0x%xn”, merge_bytes(x,y));
       ^
HW3.c:35:11: error: use of undeclared identifier 'Merged'
printf(“Merged number = 0x%xn”, merge_bytes(x,y));
        ^
HW3.c:35:33: error: non-ASCII characters are not allowed outside of literals and
      identifiers
printf(“Merged number = 0x%xn”, merge_bytes(x,y));
                              ^
HW3.c:37:8: error: non-ASCII characters are not allowed outside of literals and
      identifiers
printf(“Replaced number = 0x%xn”, replace_byte(x,3,z));
       ^
HW3.c:37:11: error: use of undeclared identifier 'Replaced'
printf(“Replaced number = 0x%xn”, 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%xn”, replace_byte(x,3,z));
                                ^
9 errors generated.

看看(“Your machine is a Little Endian machinen”); .请注意"弯曲引号":这些显然不是 ASCII 引号(看起来像这样:" )。您必须用"直引号"替换这些。(这也适用于所有其他字符串)。

不要在任何不是正确文本编辑器的内容中编辑代码。特别是,不要在MS Word,写字板或富文本编辑器中编辑代码,因为您可能会遇到这样的有趣问题。

如果您确实复制和粘贴,则可能会遇到这些问题。答案是删除所有@,"等符号,然后使用键盘重做它们。希望这有帮助。

关键是你正在使用像MS Word文本符号,这些在c或其他编程语言中是不允许的,你知道C是大小写敏感的。例如,当您阅读有关 c 编程的 pdf 文档并复制一些源代码并将它们粘贴到文本编辑器或编译器中时,您大多会遇到这些类型的错误。

ex:char s3 [100] = {'a','b','\0','d'};//correct

字符 s3 [] = {'S

','t','u','d','i','\0','e','r','e','e','r'};//不允许

因此,最好重写代码而不是复制它们并粘贴到编辑器中。

最新更新