Lost_dream_man 2022-06-25 11:37 采纳率: 50%
浏览 21

strcmp读取错误怎么办啊


#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];
    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;
    printf("请问您要输入多少个信息?");
    scanf("%d", &lo);
    printf("确认输入%d个信息\n开始输入您的信息", lo);
    for (i = 0;i<lo;i++)
    {
        scanf("%d %s %c %d %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;
        sprintf(nty[i].iuy, "%lld", a);
        sprintf(nty[i].tyu, "%lld", d);


    }
    printf("请问您要查询哪个学号?\n");
    scanf("%lld", &op);
    sprintf(uio, "%lld", op);
    i = 0;
    int r = strcmp(uio, nty[i].iuy);   **//在这个下面三行加过assert判断nty[i].iuy和r和uio是否为0,都不为0。下面还是出错**
    while (r!=0)
    {
        i++;
        r = strcmp(uio, nty[i].iuy);
    }
    printf("学号为%s 姓名为%s 性别为%c 手机号为%s 语文成绩为%f 数学成绩为%f 英语成绩为%f 品德分为%f 综合评测分为%f 排名为 备注为%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, stu[i].attach);
}

img

  • 写回答

1条回答 默认 最新

  • a5156520 2022-06-25 14:38
    关注

    修改了下回答,如下:

    #define _CRT_NONSTDC_NO_DEPRECATE
    #define _CRT_SECURE_NO_DEPRECATE
    #include<assert.h>
    #include<stdio.h>
    #include <string.h>
    
    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];
        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;
        printf("请问您要输入多少个信息?");
        scanf("%d", &lo);
        printf("确认输入%d个信息\n开始输入您的信息:\n", lo);
        for (i = 0;i<lo;i++)
        {
            // 根据你的提示,在这里将a和d对应的格式说明符修改为%lld 
            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;
            sprintf(nty[i].iuy, "%lld", a);
            sprintf(nty[i].tyu, "%lld", d);
     
     
        }
        printf("请问您要查询哪个学号?\n");
        scanf("%lld", &op);
        sprintf(uio, "%lld", op);
        i = 0;
        int r = strcmp(uio, nty[i].iuy);   //在这个下面三行加过assert判断nty[i].iuy和r和uio是否为0,都不为0。下面还是出错**
        while (r!=0)
        {
            i++;
            r = strcmp(uio, nty[i].iuy);
        }
        printf("学号为%s 姓名为%s 性别为%c 手机号为%s 语文成绩为%f 数学成绩为%f 英语成绩为%f 品德分为%f 综合评测分为%f 排名为 备注为%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, stu[i].attach);
    }
    

    img

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 6月25日

悬赏问题

  • ¥15 Xsheii7我安装这个文件的时候跳出来另一个文件已锁定文件的无一部分进程无法访问。这个该怎么解决
  • ¥15 unity terrain打包后地形错位,跟建筑不在同一个位置,怎么办
  • ¥15 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)
  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式
  • ¥15 如果要做一个老年人平板有哪些需求