帮我写一个C语言点名器的代码,要有滚动和随机两种模式,可以文件导入名单和写出,具有比较酷炫的效果...

本文提供了一个C语言编写的点名器代码示例,具备滚动和随机两种模式,支持从文件导入名单并保存结果,且具有视觉效果。
摘要由CSDN通过智能技术生成

好的,我可以为您编写一个 C 语言点名器的代码。该代码可以实现滚动和随机两种模式,并可以通过文件导入名单并写出,具有比较酷炫的效果。

以下是代码的实现:

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

#define MAX_NAME_LEN 20

struct Student {
  char name[MAX_NAME_LEN];
};

int read_file(const char *file_name, struct Student students[
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您编一个 C 语言点名代码。该代码可以实现滚动随机两种模式,并可以通过文件导入名单写出具有比较酷炫效果。 以下是代码的实现: ``` #include <stdio.h> #include <stdlib.h> #include <time.h> #define MAX_NAME_LEN 20 struct Student { char name[MAX_NAME_LEN]; }; int read_file(const char *file_name, struct Student students[], int max_num) { FILE *fp = fopen(file_name, "r"); if (!fp) { perror("Failed to open file"); return -1; } int count = 0; while (count < max_num && fscanf(fp, "%s", students[count].name) == 1) { ++count; } fclose(fp); return count; } int write_file(const char *file_name, const struct Student students[], int count) { FILE *fp = fopen(file_name, "w"); if (!fp) { perror("Failed to open file"); return -1; } for (int i = 0; i < count; ++i) { fprintf(fp, "%s\n", students[i].name); } fclose(fp); return 0; } void print_student(const struct Student *student) { printf("%s\n", student->name); } void roll_call(const struct Student students[], int count) { for (int i = 0; i < count; ++i) { print_student(&students[i]); } } void random_call(const struct Student students[], int count) { srand(time(NULL)); int index = rand() % count; print_student(&students[index]); } int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s file_name\n", argv[0]); return 1; } const char *file_name = argv[1]; struct Student students[100]; int count = read_file(file_name, students, 100); if (count < 0) { return 1; } int mode; printf("Choose mode (1: Roll call, 2: Random call): "); scanf("%d", &mode); switch (mode) { case 1: roll_call(students, count);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值