随机点名器

(C语言阶段小项目之随机点名器## 随机点名器)

要求
/*使用C语言,制作一个在命令行运行的点名程序,该程序运行时可指定班级的花名册文件,
运行后在界面上显示随机抽取名字的过程,速度由快到慢,逐渐定格到某一个“幸运儿”上,程序结束。
*/

/必做要求
1.指定普通文本文件(
.txt)为名单,以行为单位读取学员名字。
2.随机抽取的过程在终端动态展现出来,如下图所示*/

#include<stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char const *argv[])
{
char name[20][20];
// 第一个函数:打开文件
//FILE * fopen(const char * restrict path, const char * restrict mode);
FILE *fd;
fd = fopen("./a.txt", “r+”);
if(fd == NULL)
{
printf(“perror:”);
}
// else
// {
// printf(“打开文件成功!!!\n”);
// }
//第二个函数:按行读取文件内容

//char * fgets(char * restrict str, int size, FILE * restrict stream);



char (*p);

do{
    
    for (size_t i = 0; i < 8; i++)
    {
        char buf[20];
        p=fgets(buf,15,fd);
        if (p==NULL)
        {
            break;
        }
        
        strcpy(name[i],p);
    }
    
    
}while(p!=NULL);

int i, n;
time_t t;
n = 5;

//void srand(unsigned seed);
srand((unsigned) time(&t));


t = time(NULL);
//printf("自 1970-01-01 起的小时数 = %ld\n", t/3600);
t /= 36000;
//int rand(void); 产生一个随机数
for(int i = 1000;i>900;i--)
{
    system("cls");
    printf("%s",name[rand() % 5]);
    t +=10000;
    usleep((t++));
    
    
}
   
`
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值