Lost_dream_man 2022-06-26 12:31 采纳率: 50%
浏览 103
已结题

给变量赋值中文汉字出错,怎么办啊


#define _CRT_NONSTDC_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
#include<assert.h>
#include<stdio.h>
#include <string>
using namespace std;
#define size 50
int main()
{
    struct student {
        int nume_student;
        char name_student[20];
        char sex_student;
        int phone_number;
        float score_yuwen;
        float score_math;
        float score_english;
        float score_pinde;
        float total_score;
        int rank;
        char attach[50];
    }stu[size];
    float v[50];
    struct num {
        char iuy[100];
        char tyu[100];
    }nty[size];
    char uio[100];
    long long int a;
    char b;
    char c;
    long long int d;
    float e;
    float f;
    float g;
    float h;
    float j;
    int k;
    char* l;
    int i;
    int lo;
    long long int op;
    int scr=0;
    printf("请问您要输入多少个信息?");
    scanf("%d", &lo);
    printf("确认输入%d个信息\n开始输入您的信息", lo);
    for (i = 0; i < lo; i++)
    {
        scanf("%lld %s %c %lld %f %f %f %f %s", &a, stu[i].name_student, &c, &d, &e, &f, &g, &h, stu[i].attach);
        stu[i].sex_student = c;
        stu[i].score_yuwen = e;
        stu[i].score_math = f;
        stu[i].score_english = g;
        stu[i].score_pinde = h;
        stu[i].total_score = e + f + g + h;
        v[i] = e + f + g + h;
        sprintf(nty[i].iuy, "%lld", a);
        sprintf(nty[i].tyu, "%lld", d);


    }
    float temp = 0;
    for (i = 0; i < lo; i++)
    {
        for (int j = lo - 1; j > i; j--)
        {
            if (v[j] < v[j - 1])
            {
                temp = v[j];
                v[j] = v[j - 1];
                v[j - 1] = temp;
            }
        }
    }
    printf("请问您要查询哪个学号?\n");
    scanf("%lld", &op);
    sprintf(uio, "%lld", op);
    i = 0;
    int r = strcmp(uio, nty[i].iuy);
    while (r != 0)
    {
        i++;
        r = strcmp(uio, nty[i].iuy);
    }
    if (stu[i].total_score >= 90 && stu[i].total_score <= 100)  //从这里开始出问题
    {
        scr="优秀";
    }
    if (stu[i].total_score <= 89 && stu[i].total_score >= 80)
    {
        scr="良好";
    }
    if (stu[i].total_score <= 79 && stu[i].total_score >= 70)
    {
        scr="中";
    }
    if (stu[i].total_score <= 69 && stu[i].total_score >= 60)
    {
        scr="及格";
    }
    if (stu[i].total_score < 60)
    {
        scr="不及格";
    }//问题在这里结束
    int yt = 0;
    float ui;
    ui = stu[i].total_score;
    while (v[yt] != ui)
    {
        yt++;
    }
    printf("学号为%s 姓名为%s 性别为%c 手机号为%s 语文成绩为%f 数学成绩为%f 英语成绩为%f 品德分为%f 综合评测分为%f 排名为%d 成绩属于%s 备注为%s", nty[i].iuy, stu[i].name_student, stu[i].sex_student, nty[i].tyu, stu[i].score_yuwen, stu[i].score_math, stu[i].score_english, stu[i].score_pinde, stu[i].total_score, lo - yt,scr, stu[i].attach);//我想在成绩属于这里加优秀还是良好的显示出来,但scr一直报错,到底是为什么,把scr改成const char*就不报错但我不知道原理而且const不是不可修改吗,我也不敢用。所以到底怎么办啊

img

img

  • 写回答

3条回答 默认 最新

  • emXiaoMing 2022-06-26 12:44
    关注

    scr是整形当然不行了,要用char scr[20]或者char* scr这样定义字符串,然后用strcpy或者memcpy拷贝字符串到scr中.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 7月6日
  • 已采纳回答 6月28日
  • 创建了问题 6月26日

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用