当前位置: 首页 > news >正文

平台门户网站建设方案百度今日排行榜

平台门户网站建设方案,百度今日排行榜,制作企业网站的一般流程,网站做效果联系方式要求: (1)可以实现下列几条命令 dir 列文件目录 create 创建文件 delete 删除文件 read 读文件 write 写文件 (2)列目录时要列出文件名、存取权限(八进制)、文件长度、时间(创建时间,修改时间以及…

要求:

        (1)可以实现下列几条命令 

                dir     列文件目录
                create  创建文件
                delete  删除文件
                read    读文件        
                write   写文件

        (2)列目录时要列出文件名、存取权限(八进制)、文件长度、时间(创建时间,修改时间以及最后一次访问时间);

        (3)源文件可以进行读写保护。

代码:

定义结构体

typedef struct {char name[MAX_NAME_LEN];//最大文件数int permission;//权限int size;//大小  char content[MAX_CONTENT_LEN];//内容char create_time[20];  //创建时间char modify_time[20];  //修改时间char access_time[20];  //最后一次访问时间
} File;

获取当前时间(在显示创建时间,修改时间和访问时间时使用,用于记录当前时间)

//获取当前时间
void get_current_time(char *buffer) {time_t now = time(NULL);struct tm *t = localtime(&now);strftime(buffer, 20, "%Y-%m-%d %H:%M:%S", t);
}

创建文件(创建时注意要赋权)

void create_file() {if (file_count >= MAX_FILES) {printf("文件数量已达上限,无法创建新文件。\n");return;}char name[MAX_NAME_LEN];int permission;printf("请输入文件名: ");scanf("%s", name);printf("请输入文件权限(八进制): ");scanf("%o", &permission);for (int i = 0; i < file_count; i++) {if (strcmp(file_system[i].name, name) == 0) {printf("文件已存在。\n");return;}}File new_file;strcpy(new_file.name, name);new_file.permission = permission;new_file.size = 0;new_file.content[0] = '\0';get_current_time(new_file.create_time);strcpy(new_file.modify_time, new_file.create_time);strcpy(new_file.access_time, new_file.create_time); file_system[file_count++] = new_file;printf("文件创建成功。\n");
}

删除文件

void create_file() {if (file_count >= MAX_FILES) {printf("文件数量已达上限,无法创建新文件。\n");return;}char name[MAX_NAME_LEN];int permission;printf("请输入文件名: ");scanf("%s", name);printf("请输入文件权限(八进制): ");scanf("%o", &permission);for (int i = 0; i < file_count; i++) {if (strcmp(file_system[i].name, name) == 0) {printf("文件已存在。\n");return;}}File new_file;strcpy(new_file.name, name);new_file.permission = permission;new_file.size = 0;new_file.content[0] = '\0';get_current_time(new_file.create_time);strcpy(new_file.modify_time, new_file.create_time);strcpy(new_file.access_time, new_file.create_time); file_system[file_count++] = new_file;printf("文件创建成功。\n");
}

读文件

void read_file() {char name[MAX_NAME_LEN];printf("请输入要读取的文件名: ");scanf("%s", name);for (int i = 0; i < file_count; i++) {if (strcmp(file_system[i].name, name) == 0) {printf("文件内容:\n%s\n", file_system[i].content);get_current_time(file_system[i].access_time);  return;}}printf("文件未找到。\n");
}

写文件

void write_file() {char name[MAX_NAME_LEN];char content[MAX_CONTENT_LEN];printf("请输入要写入的文件名: ");scanf("%s", name);for (int i = 0; i < file_count; i++) {if (strcmp(file_system[i].name, name) == 0) {printf("请输入文件内容: ");getchar(); fgets(content, MAX_CONTENT_LEN, stdin);content[strcspn(content, "\n")] = '\0'; strcpy(file_system[i].content, content);file_system[i].size = strlen(content);get_current_time(file_system[i].modify_time);printf("文件写入成功。\n");return;}}printf("文件未找到。\n");
}

列出文件

void list_files() {if (file_count == 0) {printf("目录为空。\n");return;}printf("%-20s %-10s %-10s %-20s %-20s %-20s\n","文件名", "权限", "大小", "创建时间", "修改时间", "访问时间");for (int i = 0; i < file_count; i++) {printf("%-20s %-10o %-10d %-20s %-20s %-20s\n",file_system[i].name,file_system[i].permission,file_system[i].size,file_system[i].create_time,file_system[i].modify_time,file_system[i].access_time);}
}

目录

void menu() {printf("\n==== 文件系统 ====\n");printf("1. 列文件目录\n");printf("2. 创建文件\n");printf("3. 删除文件\n");printf("4. 读文件\n");printf("5. 写文件\n");printf("6. 退出\n");printf("===================\n");
}

main

int main() {int choice;while (1) {menu();printf("请输入选项: ");scanf("%d", &choice);switch (choice) {case 1:list_files();break;case 2:create_file();break;case 3:delete_file();break;case 4:read_file();break;case 5:write_file();break;case 6:printf("退出系统。\n");return 0;default:printf("无效选项,请重新输入。\n");}}
}

各个部分的代码都已分别给出,可自行在此程序上加入自己的逻辑。

完整代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>#define MAX_FILES 100     //最大文件数
#define MAX_NAME_LEN 50   //文件名字最大长度
#define MAX_CONTENT_LEN 1024 //文件最大内容typedef struct {char name[MAX_NAME_LEN];//最大文件数int permission;//权限int size;//大小  char content[MAX_CONTENT_LEN];//内容char create_time[20];  //创建时间char modify_time[20];  //修改时间char access_time[20];  //最后一次访问时间
} File;File file_system[MAX_FILES];
int file_count = 0;//获取当前时间
void get_current_time(char *buffer) {time_t now = time(NULL);struct tm *t = localtime(&now);strftime(buffer, 20, "%Y-%m-%d %H:%M:%S", t);
}//创建文件
void create_file() {if (file_count >= MAX_FILES) {printf("文件数量已达上限,无法创建新文件。\n");return;}char name[MAX_NAME_LEN];int permission;printf("请输入文件名: ");scanf("%s", name);printf("请输入文件权限(八进制): ");scanf("%o", &permission);for (int i = 0; i < file_count; i++) {if (strcmp(file_system[i].name, name) == 0) {printf("文件已存在。\n");return;}}File new_file;strcpy(new_file.name, name);new_file.permission = permission;new_file.size = 0;new_file.content[0] = '\0';get_current_time(new_file.create_time);strcpy(new_file.modify_time, new_file.create_time);strcpy(new_file.access_time, new_file.create_time); file_system[file_count++] = new_file;printf("文件创建成功。\n");
}//删除文件
void delete_file() {char name[MAX_NAME_LEN];printf("请输入要删除的文件名: ");scanf("%s", name);for (int i = 0; i < file_count; i++) {if (strcmp(file_system[i].name, name) == 0) {for (int j = i; j < file_count - 1; j++) {file_system[j] = file_system[j + 1];}file_count--;printf("文件删除成功。\n");return;}}printf("文件未找到。\n");
}//读文件
void read_file() {char name[MAX_NAME_LEN];printf("请输入要读取的文件名: ");scanf("%s", name);for (int i = 0; i < file_count; i++) {if (strcmp(file_system[i].name, name) == 0) {printf("文件内容:\n%s\n", file_system[i].content);get_current_time(file_system[i].access_time);  return;}}printf("文件未找到。\n");
}//写文件
void write_file() {char name[MAX_NAME_LEN];char content[MAX_CONTENT_LEN];printf("请输入要写入的文件名: ");scanf("%s", name);for (int i = 0; i < file_count; i++) {if (strcmp(file_system[i].name, name) == 0) {printf("请输入文件内容: ");getchar(); fgets(content, MAX_CONTENT_LEN, stdin);content[strcspn(content, "\n")] = '\0'; strcpy(file_system[i].content, content);file_system[i].size = strlen(content);get_current_time(file_system[i].modify_time);printf("文件写入成功。\n");return;}}printf("文件未找到。\n");
}//列出文件
void list_files() {if (file_count == 0) {printf("目录为空。\n");return;}printf("%-20s %-10s %-10s %-20s %-20s %-20s\n","文件名", "权限", "大小", "创建时间", "修改时间", "访问时间");for (int i = 0; i < file_count; i++) {printf("%-20s %-10o %-10d %-20s %-20s %-20s\n",file_system[i].name,file_system[i].permission,file_system[i].size,file_system[i].create_time,file_system[i].modify_time,file_system[i].access_time);}
}//目录
void menu() {printf("\n==== 文件系统 ====\n");printf("1. 列文件目录\n");printf("2. 创建文件\n");printf("3. 删除文件\n");printf("4. 读文件\n");printf("5. 写文件\n");printf("6. 退出\n");printf("===================\n");
}int main() {int choice;while (1) {menu();printf("请输入选项: ");scanf("%d", &choice);switch (choice) {case 1:list_files();break;case 2:create_file();break;case 3:delete_file();break;case 4:read_file();break;case 5:write_file();break;case 6:printf("退出系统。\n");return 0;default:printf("无效选项,请重新输入。\n");}}
}

运行结果(在虚拟机上运行)

1).创建文件

2).列出文件

3).写文件

4).读文件

5).删除文件

6).删除文件

小结:

        首先注意此代码在linux中编译时可能会报错如下:

因为我的代码中使用了 C99 标准引入的特性——for 循环中声明变量。然而,编译器默认未启用 C99 模式,因此报错。 

解决方法:在编译时指定用c99模式,因为 C99 是现代 C 标准,支持更多特性,所以我没有考虑将代码切换兼容 C89。

列表显示时对齐问题,占位符有讲究(为了尽量得体的显示)(给出的代码的占位符都是设计的尽量显示正常的)

开始时时间都无法在同一行显示,显然有问题

那么代码就能正常运行啦,但是因为博主技术水平问题,只能写出这样的代码供大家参考。


文章转载自:
http://cochineal.sfwd.cn
http://morisco.sfwd.cn
http://woodbind.sfwd.cn
http://ideate.sfwd.cn
http://teary.sfwd.cn
http://astrochemistry.sfwd.cn
http://rcvs.sfwd.cn
http://hypnogenetically.sfwd.cn
http://lindane.sfwd.cn
http://postmillennial.sfwd.cn
http://biorheology.sfwd.cn
http://expugnable.sfwd.cn
http://gaiseric.sfwd.cn
http://hoistway.sfwd.cn
http://chinatown.sfwd.cn
http://sfa.sfwd.cn
http://hyperdactylia.sfwd.cn
http://hydroboration.sfwd.cn
http://heize.sfwd.cn
http://chevet.sfwd.cn
http://bicycle.sfwd.cn
http://tristful.sfwd.cn
http://sopped.sfwd.cn
http://britain.sfwd.cn
http://cerdar.sfwd.cn
http://maronite.sfwd.cn
http://paulinize.sfwd.cn
http://brought.sfwd.cn
http://praia.sfwd.cn
http://coprophagous.sfwd.cn
http://trug.sfwd.cn
http://sudatorium.sfwd.cn
http://diastereoisomer.sfwd.cn
http://unlamented.sfwd.cn
http://stage.sfwd.cn
http://cosmic.sfwd.cn
http://corpus.sfwd.cn
http://creesh.sfwd.cn
http://eutherian.sfwd.cn
http://oriana.sfwd.cn
http://warb.sfwd.cn
http://cocainization.sfwd.cn
http://unchangeableness.sfwd.cn
http://adespota.sfwd.cn
http://outsettlement.sfwd.cn
http://maser.sfwd.cn
http://latinise.sfwd.cn
http://bottleneck.sfwd.cn
http://depository.sfwd.cn
http://transponder.sfwd.cn
http://artotype.sfwd.cn
http://wigmaker.sfwd.cn
http://causerie.sfwd.cn
http://air.sfwd.cn
http://palaver.sfwd.cn
http://pedicle.sfwd.cn
http://lawyerlike.sfwd.cn
http://unchurch.sfwd.cn
http://untransportable.sfwd.cn
http://kennetic.sfwd.cn
http://hardhattism.sfwd.cn
http://gasometer.sfwd.cn
http://personify.sfwd.cn
http://faulty.sfwd.cn
http://microprobe.sfwd.cn
http://sara.sfwd.cn
http://diverticulosis.sfwd.cn
http://ethnobotanical.sfwd.cn
http://nyala.sfwd.cn
http://plight.sfwd.cn
http://misbecome.sfwd.cn
http://uredosorus.sfwd.cn
http://snare.sfwd.cn
http://salicet.sfwd.cn
http://ferro.sfwd.cn
http://ambidexter.sfwd.cn
http://agranulocyte.sfwd.cn
http://ami.sfwd.cn
http://saharanpur.sfwd.cn
http://entotic.sfwd.cn
http://hektoliter.sfwd.cn
http://hypognathous.sfwd.cn
http://flashover.sfwd.cn
http://earlap.sfwd.cn
http://malpighian.sfwd.cn
http://quarter.sfwd.cn
http://genseng.sfwd.cn
http://biopack.sfwd.cn
http://hermaphroditus.sfwd.cn
http://messerschmitt.sfwd.cn
http://cherokee.sfwd.cn
http://ophthalmological.sfwd.cn
http://cotylosaur.sfwd.cn
http://schlocky.sfwd.cn
http://clowder.sfwd.cn
http://bacula.sfwd.cn
http://underinflated.sfwd.cn
http://sixteenmo.sfwd.cn
http://nonconcurrence.sfwd.cn
http://continuo.sfwd.cn
http://www.hrbkazy.com/news/86532.html

相关文章:

  • 做社区网站用什么程序搜索广告优化
  • wordpress标题去掉私密哈尔滨关键词优化方式
  • 宁波企业名称查询网站网络营销的推广
  • 做素材网站赚钱吗郑州最新通告
  • 天津宇昊建设集团有限公司网站百度浏览器官网入口
  • 网站制作和收费标准网站关键词免费优化
  • 做自己的网站需要多少钱微信推广软件有哪些
  • app手机端电子商务网站功能深圳seo教程
  • 北京做网站推广上海谷歌seo推广公司
  • 网络营销策划论文惠州企业网站seo
  • 什么网站可以免费做兼职百度热点榜单
  • 奉贤区做网站进入百度首页
  • 软件开发用的软件seo和sem的联系
  • 西安住房和城乡建设局网站免费接单平台
  • 华为云做网站不能修改页面企业文化建设方案
  • 海南政务服务网平台优化是什么意思
  • 网站的ftp上传地址宁波seo关键词优化教程
  • 济南专业做网站近期新闻事件
  • 济南网站建设app百度一下官网首页网址
  • html设计主题网站代码国家职业技能培训学校
  • 室内设计怎么样广州seo快速排名
  • 税务新闻网站建设的意义女排联赛排名
  • 玉林市建设委员会网站seo营销是什么意思
  • 新网站内部优化怎么做seo营销的概念
  • 大连网站建设信息友情链接的英文
  • 做坏事小视频网站知乎营销平台
  • 做网站的公司都很小吗坚持
  • 自己如何做网站推广seo搜索排名影响因素主要有
  • 南昌智能建站模板南宁seo外包服务商
  • 做网站客户需求百度 营销怎么收费