|
发表于 2021-11-12 12:17:31
|
显示全部楼层
本帖最后由 jhq999 于 2021-11-12 12:28 编辑
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <conio.h>
- typedef struct STUDENT
- {
- int ID;
- char stname[16];
- STUDENT *next;
- }Student,*pStudent;
- int OutrndID(int stsum);
- int CallID(int stsum);
- pStudent Outst(int ID);
- pStudent Outst(int ID)
- {
- pStudent tmp=firstST.next;
- while ((ID!=tmp->ID))
- {
- tmp=tmp->next;
- if (NULL==tmp)break;
- }
-
- return tmp;
- }
- int OutrndID(int stsum)
- {
- return (rand()%stsum)+1;
- }
- int CallID(int stsum)
- {
- STUDENT firstST={0};
- int i=0,j=0;
- pStudent tmp=&firstST;
- for(i=1;i<=stsum;i++)
- {
- pStudent pst=(pStudent)malloc(sizeof(STUDENT));
- tmp->next=pst;
- pst->ID=i;
- for (j = 0; j < sizeof(pst->stname); j++)
- {
- pst->stname[j]='\0';
- }
- pst->next=NULL;
- tmp=pst;
- }
- srand((unsigned int)(time(NULL)));
- char inputch=0;
-
- while (1)
- {
- printf("输入空格:");
- //scanf("%c",&inputch);
- inputch=_getch();
- printf("\n");
- if (0x20!=inputch)
- {
- printf("是否退出(Y/N)?");
- inputch=getchar();
- if (('Y'==inputch)||('y'==inputch))
- {
- break;
- }
- continue;
- }
- if (NULL==(tmp=Outst(OutrndID(stsum))))
- {
- printf("没有找到!");
- }
- if (!tmp->stname[0])
- {
- printf("(学号:%d)没有录入名字,请录入:\n",tmp->ID);
- scanf("%s",tmp->stname);
- getchar();
- }
- else
- {
- printf("(学号:%d)姓名:%s\n",tmp->ID,tmp->stname);
- }
- }
- if (NULL!=firstST.next)
- {
- tmp=firstST.next->next;
- free(firstST.next);
- firstST.next=tmp;
- }
- return 0;
- }
- int main ()
- {
- CallID(5);
-
- return 0;
- }
复制代码 |
|