学生的信息_h

typedef struct student { int id; char name[20]; char sex; int age; struct student *next; }Student; Student *head = (Student*) malloc(sizeof(Student)); Student *pCur = head; head->next = NULL; do { printf("Please input id, name, sex, age: "); scanf("%d %s %c %d", &id, name, &sex, &age); if (0 == id) { break; } Student *pTmp = (Student*) malloc(sizeof(Student)); pTmp->id = id; strcpy(pTmp->name, name); pTmp->sex = sex; pTmp->age = age; pCur->next = pTmp; pCur = pTmp; } while (1); pPre = head; pCur = head->next; while (NULL != pCur) { free(pPre); printf("%d,%s,%c,%d/n",pCur->id,pCur->name,pCur->sex,pCur->age); pPre = pCur; pCur = pCur->next; }  

你可能感兴趣的:(c,struct,null,input)