|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这个编译是没有问题的,可是在我刚输入完后就会弹出:“unhandled exception”,不知是哪里有错。
#include <stdio.h>
#include <conio.h>
void main()
{
int i;
char *name;
struct person
{
int vote;
char *name;
} one ={0,"小甲鱼"}, two={0,"大"}, three={0,"小"}, four={0,"中"};
printf("\n欢迎进入良好公民投票系统!:)\n");
printf("\n本次的候选人有:小甲鱼、大、小、中\n");
printf("\n一共可以投3票,请选出您心目中的最佳候选人吧!\n");
for(i=0;i<3;i++)
{
printf("\n请输入第%d次投票结果:\n",i);
scanf("%s",&name);
if(*name=="小甲鱼")
{
one.vote++;
}
else if(*name=="大")
{
two.vote++;
}
else if(*name=="小")
{
three.vote++;
}
else if(*name=="中")
{
four.vote++;
}
else
continue;
}
printf("\n%s的的票数是:%d\n",one.name,one.vote);
printf("\n%s的的票数是:%d\n",two.name,two.vote);
printf("\n%s的的票数是:%d\n",three.name,three.vote);
printf("\n%s的的票数是:%d\n",four.name,four.vote);
getch();
}
希望能帮忙指正一下,谢谢。
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
int i;
char *name;
struct person
{
int vote;
char *name;
} one = {0, "小甲鱼"}, two = {0, "大"}, three = {0, "小"}, four = {0, "中"};
printf("\n欢迎进入良好公民投票系统!:)\n");
printf("\n本次的候选人有:小甲鱼、大、小、中\n");
printf("\n一共可以投3票,请选出您心目中的最佳候选人吧!\n");
name = malloc(1024);
for(i = 0; i < 3; i++)
{
printf("\n请输入第%d次投票结果:\n", i);
scanf("%s", name);
if(strcmp(name, "小甲鱼") == 0)
{
one.vote++;
}
else if(strcmp(name, "大") == 0)
{
two.vote++;
}
else if(strcmp(name, "小") == 0)
{
three.vote++;
}
else if(strcmp(name, "中") == 0)
{
four.vote++;
}
else
continue;
}
printf("\n%s的的票数是:%d\n", one.name, one.vote);
printf("\n%s的的票数是:%d\n", two.name, two.vote);
printf("\n%s的的票数是:%d\n", three.name, three.vote);
printf("\n%s的的票数是:%d\n", four.name, four.vote);
getch();
}
1>------ 已启动全部重新生成: 项目: C, 配置: Debug Win32 ------
1>main.c
1>C:\VisualStudioProjects\C\C\main.c(34,1): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\stdio.h(1274): message : 参见“scanf”的声明
1>C:\VisualStudioProjects\C\C\main.c(58,1): warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _getch. See online help for details.
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\conio.h(453): message : 参见“getch”的声明
1>C.vcxproj -> C:\VisualStudioProjects\C\Debug\C.exe
1>已完成生成项目“C.vcxproj”的操作。
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
|
|