//设有三个候选人,每次输入一个候选人名字
//要求最后输出三个候选人的得票数
#include<stdio.h>
#include<string.h>
struct  Person             
{
    char name[10];
    int count;
};
int main()
{
    struct Person p1={"张三",0},p2={"李四",0},p3={"王二",0};

    int i,j;
    char leader_name[10];
    for(i=0;i<3;i++)
    {
        printf("please input the name:\n");
        scanf("%s",leader_name);
        if(strcmp(leader_name,p1.name)==0)
            p1.count++;
        else
            if(strcmp(leader_name,p2.name)==0)
            p2.count++;
        else
            if(strcmp(leader_name,p3.name)==0)
            p3.count++;

    }
    printf("%s,count=%d\n",p1.name,p1.count);
    printf("%s,count=%d\n",p2.name,p2.count);
    printf("%s,count=%d\n",p3.name,p3.count);
    return 0;
}

结构体初级

 

相关文章:

  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2021-10-21
  • 2021-11-23
  • 2021-07-13
猜你喜欢
  • 2021-07-31
  • 2021-11-23
  • 2022-12-23
  • 2021-11-23
  • 2021-11-23
相关资源
相似解决方案