gpt4 book ai didi

c - 我打印结构信息的代码有什么问题?

转载 作者:行者123 更新时间:2023-11-30 16:48:08 25 4
gpt4 key购买 nike

#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <ctype.h>

struct ALUMNO{
int cod;
char nombre[20], grupo[3], app[20], apm[20];
float prom,cali[5];
} al[20]={'\0'};

void gotoxy(int x,int y){
HANDLE hcon;
hcon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD dwPos;
dwPos.X = x;
dwPos.Y= y;
SetConsoleCursorPosition(hcon,dwPos);
}

int main()
{
char gru[3];
int x = 0, sw, ac;
al[0].cod=12345;
strcpy(al[0].grupo,"1A");
strcpy(al[0].nombre,"Erick");
strcpy(al[0].app,"Medina");
strcpy(al[0].apm,"Ramirez");
al[0].prom=0.0;

al[1].cod=12346;
strcpy(al[1].grupo,"1A");
strcpy(al[1].nombre,"Emmanuel");
strcpy(al[1].app,"Sauceda");
strcpy(al[1].apm,"Perez");
al[1].prom=0.0;

al[2].cod=12347;
strcpy(al[2].grupo,"1B");
strcpy(al[2].nombre,"Vincio");
strcpy(al[2].app,"Lopez");
strcpy(al[2].apm,"Martinez");
al[2].prom=0.0;
//salon B
al[3].cod=12348;
strcpy(al[3].grupo,"1B");
strcpy(al[3].nombre,"Bryan");
strcpy(al[3].app,"Osuna");
strcpy(al[3].apm,"Beltran");
al[3].prom=0.0;

al[4].cod=12349;
strcpy(al[4].grupo,"1C");
strcpy(al[4].nombre,"Fullano");
strcpy(al[4].app,"Mangano");
strcpy(al[4].apm,"Centenario");
al[4].prom=0.0;

al[5].cod=12350;
strcpy(al[5].grupo,"1C");
strcpy(al[5].nombre,"Chapo");
strcpy(al[5].app,"Guzman");
strcpy(al[5].apm,"Loera");
al[5].prom=0.0;
//done

printf("Grupo: ");
scanf("%s",&gru);
gru[1]=toupper(gru[1]);
system("cls");
printf("Codigo\tAp.paterno\tap.materno\tnombre\tpromedio");
for (x=0, sw=0; x<25 && al[x].cod!=0; x++){
if (strcmp(gru,al[x].grupo)==0){
sw=1;
ac++;
}
if (sw==1){
gotoxy(1,ac);
printf("%i",al[x].cod);
gotoxy(12,ac);
printf("%s",al[x].app);
gotoxy(30,ac);
printf("%s",al[x].apm);
gotoxy(50,ac);
printf("%s",al[x].nombre);
gotoxy(60,ac);
printf("%.2f",al[x].prom);
}
}
ac=0;
}

出于某种原因,当您输入正确的组并按 Enter 键时,它会将母亲的姓氏打印在其他姓氏之上。或者某些名称可能丢失,或者这只是我的编译器。当每个组只有一个名称时,它可以正常工作。

最佳答案

您的gru变量在scanf中使用错误。应该是 gru,而不是 &gru

顺便说一句,不要使用scanf,使用fgets

关于c - 我打印结构信息的代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43080819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com