posts - 137,comments - 0,views - 40818
复制代码
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <conio.h>
using namespace std;
struct hero {
    char name[16];
    char sex; //W代表女,M代表男;
    int strong;
    int age;
}; //hero; //第一种用法
struct hero hero;  //第二种用法
int main(void) {
    //struct hero hero;  //第三种用法
    printf("请输入英雄的姓名:");
    scanf_s("%s",hero.name,sizeof(hero.name));

    printf("请输入英雄的性别:");
    cin.ignore((numeric_limits<std::streamsize>::max)(), '\n');
    scanf_s("%c", &hero.sex, sizeof(hero.sex));//这里会吃掉回车符,所以要清除缓冲区

    printf("请输入英雄的武力值:");
    scanf_s("%d", &hero.strong);

    printf("请输入英雄的年龄:");
    scanf_s("%d", &hero.age);

    printf("\n-----角色信息表-----\n");
    printf("【姓名】:%s\n",hero.name);
    printf("【性别】:%c\n", hero.sex);
    printf("【武力值】:%d\n", hero.strong);
    printf("【年龄】:%d\n", hero.age);

    system("pause");
    return 0;
}
复制代码

posted on   wshidaboss  阅读(142)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
· Manus的开源复刻OpenManus初探
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示