|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 理想小青年 于 2018-5-12 16:31 编辑
- #include <stdio.h>
- #define M 3
- #define F 2
- struct dog
- {
- char name[20];
- int sroce[2];
- };
- void main()
- {
- int i,j;
- char ch[10];
- char *chh = ch;
- struct dog man[M][F]={{"二哈",0},{"金毛",0},{"萨摩",0}};//一个结构化二维数组
- printf("欢迎参加狗王选拔:\n");
- printf("狗王候选:二哈,金毛,萨摩\n");
- for(i=0;i<5;i++) //一共投票五次(5人选票)
- {
- printf("第%d位投选狗王,请输入你支持的狗王: ",i+1);
- gets(chh);//接收选票名字
- for(j=0;j<M;j++)
- {
- if(strcmp(man[j]->name,chh))
- {
- continue;
- }
- else
- {
- printf("%d\n",man[j]->sroce);
- //man[j]->sroce += 1;//选举字符串 与 数组一样,累计+1
- }
- }
- }
- for(i=0;i<M;i++)
- {
- printf("%s的选票数为: %d票\n",man[i]->name,man[i]->sroce);
- }
- }
复制代码
为什么man[j]->sroce不应该取值是一个int类型的数吗?为什么是一串未知的数组1开头的,初始化为0,累计+=1的话会报错error C2106: '+=' : left operand must be l-value
不懂 求大神指点 |
|