#include #include #include typedef struct game { char name[8]; /* 參賽者姓名 */ int score; /* 得分 */ }GAME; int main(){ int i=0 ,j=0 ,n ; GAME temp; char input[20]; GAME * bowling = (GAME*)malloc(sizeof(GAME)); printf("輸入參賽者資訊\n"); while(1){ printf("第%d位參賽者名字 得分 => ",i+1); // fgets(input,sizeof(input),stdin); if(fgets(input,sizeof(input),stdin) == NULL||(strcmp(input,"\n")) == 0 ){ break; } bowling = (GAME*)realloc(bowling ,(i+1)* sizeof(GAME)); sscanf(input,"%s%d",bowling[i].name,&bowling[i].score); i++; n=i; } for(i=0;i