《C语言随机点名(最新整理)》由会员分享,可在线阅读,更多相关《C语言随机点名(最新整理)(10页珍藏版)》请在人人文库网上搜索。
1、include #include #include #define STU_NUM_MAX 64 / 假设最多有 64 个学生struct Studentchar name10; int stuID;stuSTU_NUM_MAX;int existSTU_NUM_MAX; / 用以保存被点过名static int index=0; / 记住点名的次数void Iitialize()for(int i=0;i #include #include #include #include struct studentinfost100;char sNo5; char sxueNo14; char sna。
2、me20;int main()int i=0,j=0,k,flag,RN,*a; FILE *fp;char ch,filename20=0,line100=0; printf(Please input file name:); fflush(stdin);gets(filename); fp=fopen(filename,r); printf(名单如下:n);while (fgets(line,sizeof(line)-1,fp)if (line0!=n & line0!= )name);me);sscanf(line,%s %s %sn,sti.sNo,sti.sxueNo,sti.spr。
3、intf(%sn%sn%sn,sti.sNo,sti.sxueNo,sti.sna i+;srand(unsigned)time(NULL); a=(int*)malloc(sizeof(int)*i); memset(a,-1,sizeof(a);printf(按任意键点名:);fflush(stdin);while (!(ch=getch()=NULL)RN=rand()%i; flag=1;for (k=0;k #include #include #define STU_NUM_MAX 4struct StudentInfo / 学生信息结构char name15; int stu_id。
4、;stuSTU_NUM_MAX;void WriteData() /写入学生信息FILE *fp;int stu_num=4;for (int i=0;i #include #include #define SIZE 4 struct student char num20;char name10;int time; stdSIZE; void save() int i; FILE *fp;if(fp=fopen(myfile.dat,rb+)=NULL)printf(文件打开失败n);exit(0); for(i=0;iSIZE;i+)沈 阳 航 院 设 计 用 纸9if(fwrite(&st。
5、di,sizeof(struct student),1,fp)!=1)/*将内存中的数据输出到磁盘文件中*/printf(文件保存失败n); void main() int j,i;char c;FILE *fp; if(fp=fopen(myfile.dat,ab+)=NULL) printf(文件打开失败n);exit(0); for(i=0;iSIZE;i+)fread(&stdi,sizeof(struct student),1,fp);/*将 fp 所指向的文件中的数据存储到数组 std 中*/printf(*欢迎使用上课随机点名程序*n); printf(*输入a:显示所有同学名情。
6、况*n);printf(*输入 d:开始点名*n); printf(*输入 s:保存点名*n); printf(*输入 b:点名次数归零*n);printf(*输入 q:退出*n); printf(*n);while(1) c=getchar();switch(c)case a: for(i=0;iSIZE;i+)printf(tt%stt%stt 被点名%d 次n,stdi.num,stdi. name,stdi.time);break;case s: save();printf(*文件保存成功!退出请输入 q*n); break;case b: for(i=0;iSIZE;i+)沈 阳 航。
7、 院 设 计 用 纸10stdi.time=0;printf(点名次数归%dn,stdi.time);break;case q:exit(0);case d: loop: j=rand()/1000;/*调用 rand 的函数进行点名*/if(j=0)std0.time+; printf(tt%stt%sn,stdj.num,stdj.name); else if(j=1)std1.time+; printf(tt%stt%sn,stdj.num,stdj.name); else if(j=2)std2.time+; printf(tt%stt%sn,stdj.num,stdj.name); 。
8、else if(j=3)std3.time+; printf(tt%stt%sn,stdj.num,stdj.name);else goto loop;break; fclose(fp); “”“”At the end, Xiao Bian gives you a passage. Minand once said, people who learn to learn are very happy people. In every wonderful life, learning is an eternal theme. As a professional clerical and teach。
9、ing position, I understand the importance of continuous learning, life is diligent, nothing can be gained, only continuous learning can achieve better self. Only by constantly learning and mastering the latest relevant knowledge, can employees from all walks of life keep up with the pace of enterprise development and innovate to meet the needs of the market. This document is also edited by my studio professionals, there may be errors in the document, if there are errors, please correct, thank you。