0
#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;
}
出於某種原因,當你在正確的組鍵入並回車,將打印在他人之上產婦姓。或者有些名字可能會丟失,或者只是我的編譯器。當你每組只有一個名字時,它工作正常。我的代碼打印結構信息有什麼問題?
爲他人謀取利益,我已經破譯基於該被打印的標題行,而「母體名」變量名是由代表明顯的結構成員'apm'。出於某種原因,控制檯光標定位已用於以表格形式呈現數據,而不是'printf'中的寬度說明符。 – paddy