好的所以我正在为课程编写代码,我认为一切都是正确的,除非我在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;
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误
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.
Run Code Online (Sandbox Code Playgroud)
nne*_*neo 15
看看(“Your machine is a Little Endian machine\n”);.注意"曲线引号":这些显然不是ASCII引号(看起来像这样:) ".你必须用"直引号"替换它们.(这也适用于所有其他字符串).
不要在任何不适当的文本编辑器中编辑代码.特别是,不要在MS Word,写字板或富文本编辑器中编辑代码,因为您可能会遇到类似这样的有趣问题.
| 归档时间: |
|
| 查看次数: |
17096 次 |
| 最近记录: |