为什么啊,C语言问题
#include<stdio.h>intmain(){intx,y;chara;//chara[][20]={"龙","兔","虎","牛","鼠","猪","狗","鸡...
#include<stdio.h>
int main()
{
int x,y;
char a;
// char
a[][20]={"龙","兔","虎","牛","鼠","猪","狗","鸡","猴","羊","马","蛇"};
scanf("%d",&y);
x=(2013-y)%12;
printf("%s\n",a[x]);
}
这是说的错误
C2018: unknown character '0xa3'
C:\Users\HP\Desktop\ab.c(4) : error C2018: unknown character '0xac'
C:\Users\HP\Desktop\ab.c(4) : error C2146: syntax error : missing ';' before identifier 'y'
C:\Users\HP\Desktop\ab.c(4) : error C2065: 'y' : undeclared identifier
C:\Users\HP\Desktop\ab.c(5) : error C2143: syntax error : missing ';' before 'type'
C:\Users\HP\Desktop\ab.c(7) : error C2065: 'a' : undeclared identifier
C:\Users\HP\Desktop\ab.c(7) : error C2059: syntax error : ']'
C:\Users\HP\Desktop\ab.c(10) : error C2109: subscript requires array or pointer type
执行 cl.exe 时出错. 展开
int main()
{
int x,y;
char a;
// char
a[][20]={"龙","兔","虎","牛","鼠","猪","狗","鸡","猴","羊","马","蛇"};
scanf("%d",&y);
x=(2013-y)%12;
printf("%s\n",a[x]);
}
这是说的错误
C2018: unknown character '0xa3'
C:\Users\HP\Desktop\ab.c(4) : error C2018: unknown character '0xac'
C:\Users\HP\Desktop\ab.c(4) : error C2146: syntax error : missing ';' before identifier 'y'
C:\Users\HP\Desktop\ab.c(4) : error C2065: 'y' : undeclared identifier
C:\Users\HP\Desktop\ab.c(5) : error C2143: syntax error : missing ';' before 'type'
C:\Users\HP\Desktop\ab.c(7) : error C2065: 'a' : undeclared identifier
C:\Users\HP\Desktop\ab.c(7) : error C2059: syntax error : ']'
C:\Users\HP\Desktop\ab.c(10) : error C2109: subscript requires array or pointer type
执行 cl.exe 时出错. 展开
5个回答
展开全部
处理汉字个人推荐宽字符
当然也有其他取巧的办法,不过个人不是很推荐
#include <stdio.h>
#include <locale.h>
int main() {
int x, y;
wchar_t a[] = L"龙兔虎牛鼠猪狗鸡猴羊马蛇";
_wsetlocale (LC_ALL, L"chs");
scanf("%d", &y);
x = (2013 - y) % 12;
wprintf (L"%c\n", a[x]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你好,已帮你改好
#include<stdio.h>
int main()
{
int x,y;//
char *a[20]={"龙","兔","虎","牛","鼠","猪","狗","鸡","猴","羊","马","蛇"};
scanf("%d",&y);
x=(2013-y)%12;
printf("%s\n",a[x]);
}
希望回答能帮到你,哪里不清楚再问。
#include<stdio.h>
int main()
{
int x,y;//
char *a[20]={"龙","兔","虎","牛","鼠","猪","狗","鸡","猴","羊","马","蛇"};
scanf("%d",&y);
x=(2013-y)%12;
printf("%s\n",a[x]);
}
希望回答能帮到你,哪里不清楚再问。
更多追问追答
追问
你这个也能正常运行,可是上次我问人,他说汉字占两个字节,必须用二维数组,可是你这一维的怎么就能运行了,还有为什么加指针。
追答
你好,所定义的char*[]表示字符指针数组,注意,它是数组,就是每一个元素都是指针指向字符类型,输出一个字符指针的地址就会把地址处及后面的所有字符都输出来直到遇到'\0'为止。
用二位数组也可以的哦。
亲,如果觉得回答对你有帮助记得采纳哦。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
int main()
{
int x=0,y;
char a;//这里应该定义成数组吧???
// char a[11]={"龙","兔","虎","牛","鼠","猪","狗","鸡","猴","羊","马","蛇"};
scanf("%d",&y);
x=(2013-y)%12;
printf("%s\n",a[x]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int x;
int y;
//char a;
char a[][20]={"龙","兔","虎","牛","鼠","猪","狗","鸡","猴","羊","马","蛇"};
scanf("%d",&y);
x=(2013-y)%12;
printf("%s\n",a[x]);
int y;
//char a;
char a[][20]={"龙","兔","虎","牛","鼠","猪","狗","鸡","猴","羊","马","蛇"};
scanf("%d",&y);
x=(2013-y)%12;
printf("%s\n",a[x]);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
char a[12][20];
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询