#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);
}

strcmp读取错误怎么办啊
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- a5156520 2022-06-25 06: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); }
解决 无用评论 打赏 举报 编辑记录