我很菜0.添加用户

这个命令不是很常用,虽然简单,但是时间长了还是记不住具体的参数,所以就用赖笔头记下来吧。

参考链接 http://www.server-world.info/en/note?os=Fedora_23&p=initial_conf

[1] Add a new user account.
[root@localhost ~]# useradd fedora

[root@localhost ~]# passwd fedora

Changing password for user fedora.
New UNIX password:

set password

Retype new UNIX password:

confirm

passwd: all authentication tokens updated successfully.
[root@localhost ~]# exit

logout

[2] Try to switch to a user that was added above.
localhost login: fedora

input user name

password:

password

[fedora@localhost ~]$ su -

switch to root

Password:

root password

[root@localhost ~]#

just switched to root

[3] Make a user (it’s [fedora] in this example) be only a user who can switch to root as an administration user.
[root@localhost ~]# usermod -G wheel fedora

[root@localhost ~]# vi /etc/pam.d/su

%PAM-1.0

auth sufficient pam_rootok.so

Uncomment the following line to implicitly trust users in the “wheel” group.

auth sufficient pam_wheel.so trust use_uid

Uncomment the following line to require a user to be in the “wheel” group.

uncomment the following line

auth required pam_wheel.so use_uid

auth substack system-auth
auth include postlogin
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
account include system-auth
password include system-auth
session include system-auth
session include postlogin
session optional pam_xauth.so

<think>我们正在开发一个家庭谱管理系统,使用C语言在VSCode中实现。基础功能包括添加、修改、删除、查询和查看全部谱。现在需要思考一些额外的功能来增强系统的实用性。 额外功能建议: 1. 分类管理:允许用户谱设置分类(如:川、粤、甜点等),并可以按分类查看谱。 2. 搜索功能:支持按名、食材或分类进行搜索,甚至支持模糊搜索(如输入部分名即可匹配)。 3. 食材管理:记录每道所需的食材,并可以统计当前家中食材可以制作哪些(需要维护一个食材库存)。 4. 收藏与评分:用户可以为喜欢的谱收藏或评分,方便以后快速找到高评价的谱。 5. 导出与导入:将谱数据导出为文件(如txt或csv格式),也可以从文件导入谱,方便备份和分享。 6. 图片支持:虽然C语言处理图片较复杂,但可以存储图片的路径,然后在其他支持图片显示的环境中查看(如将谱导出为HTML格式,包含图片链接)。 7. 烹饪时间记录:记录每道的烹饪时间,方便用户根据可用时间选择谱。 8. 难度级别:设置谱的难度级别(初级、中级、高级),帮助用户选择适合自己烹饪水平的谱。 9. 最近浏览:记录用户最近查看的谱,方便快速访问。 10. 计划单:允许用户谱中选择多道,生成一个单(例如一周的单),并可以打印或导出。 由于C语言是面向过程的,我们将使用结构体来表示谱,并使用文件来存储数据。下面是一个简单的设计示例: 谱结构体可能包括: - 名 - 分类 - 食材(可以是一个字符串数组,或者一个字符串,用逗号分隔) - 烹饪步骤 - 烹饪时间 - 难度 - 评分 - 图片路径(可选) 我们将使用文件(如recipes.dat)来存储谱记录。每次程序启动时加载到内存(链表或数组),退出时保存。 下面是一个简单的代码框架: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> // 谱结构体 typedef struct { char name[50]; // 名 char category[30]; // 分类 char ingredients[200]; // 食材,用逗号分隔 char steps[500]; // 步骤 int time; // 烹饪时间(分钟) int difficulty; // 难度:1-简单,2-中等,3-困难 float rating; // 评分(0-5) // 可以添加图片路径 char image_path[100]; } Recipe; // 全局变量:谱数组和数量 Recipe *recipes = NULL; int recipe_count = 0; // 函数声明 void load_recipes(); void save_recipes(); void add_recipe(); void display_all(); // 其他函数声明... int main() { load_recipes(); // 主单循环 int choice; do { printf("\n家庭谱管理系统\n"); printf("1. 添加谱\n"); printf("2. 显示所有谱\n"); printf("3. 修改谱\n"); printf("4. 删除谱\n"); printf("5. 查询谱\n"); printf("6. 按分类查看\n"); printf("7. 退出\n"); printf("请选择: "); scanf("%d", &choice); getchar(); // 吸收换行符 switch(choice) { case 1: add_recipe(); break; case 2: display_all(); break; // 其他功能 case 7: save_recipes(); break; } } while(choice != 7); // 释放内存 free(recipes); return 0; } void load_recipes() { // 从文件recipes.dat中读取谱 FILE *file = fopen("recipes.dat", "rb"); if (file == NULL) { return; // 文件不存在,则直接返回 } // 读取谱数量 fread(&recipe_count, sizeof(int), 1, file); recipes = (Recipe*)malloc(recipe_count * sizeof(Recipe)); fread(recipes, sizeof(Recipe), recipe_count, file); fclose(file); } void save_recipes() { FILE *file = fopen("recipes.dat", "wb"); if (file == NULL) { printf("保存失败!\n"); return; } // 先写入谱数量 fwrite(&recipe_count, sizeof(int), 1, file); fwrite(recipes, sizeof(Recipe), recipe_count, file); fclose(file); } void add_recipe() { // 增加谱数量,重新分配内存 recipes = (Recipe*)realloc(recipes, (recipe_count+1)*sizeof(Recipe)); Recipe *r = &recipes[recipe_count]; printf("请输入名: "); fgets(r->name, 50, stdin); r->name[strcspn(r->name, "\n")] = '\0'; // 去掉换行符 printf("请输入分类: "); fgets(r->category, 30, stdin); r->category[strcspn(r->category, "\n")] = '\0'; // 其他信息的输入... recipe_count++; } void display_all() { for (int i = 0; i < recipe_count; i++) { printf("名: %s\n", recipes[i].name); printf("分类: %s\n", recipes[i].category); // 打印其他信息 printf("-------------------\n"); } } ``` 注意:上述代码是一个简化的框架,实际开发中需要完善错误处理、输入验证等功能。另外,对于字符串输入,使用fgets可以避免缓冲区溢出,但要注意处理换行符。 由于C语言没有内置的字符串分割函数,如果需要处理食材列表(例如分割成数组),可以使用strtok函数。但在这个简单版本中,我们用一个字符串存储所有食材。 此外,对于大量数据,使用链表可能比数组更合适(因为数组需要频繁重新分配内存),但这里为了简单使用了动态数组。 扩展功能如搜索、按分类查看等,需要编写相应的函数,并在主单中添加选项。 以上是一个基础版本,你可以根据需求逐步完善。 相关问题: 1. 如何改进这个系统以支持图片显示? 2. 在C语言中如何实现模糊搜索? 3. 如何优化数据结构以提高谱搜索的效率? 4. 如何设计一个友好的用户界面(命令行下)? 5. 如何实现用户登录和多用户支持?</think>### 基于C语言的家庭谱管理系统开发建议 #### 基础功能实现方案 1. **数据结构设计** 建议使用结构体存储谱信息: ```c typedef struct { int id; // 唯一标识 char name[50]; // 名 char category[30]; // 分类(川/甜点等) char ingredients[200]; // 食材列表 char steps[500]; // 烹饪步骤 int prep_time; // 准备时间(分钟) } Recipe; ``` 2. **文件存储** 使用二进制文件保存数据(如`recipes.dat`),通过`fread/fwrite`实现持久化存储。 3. **核心函数框架**: ```c void add_recipe(); void edit_recipe(int id); void delete_recipe(int id); void search_recipe(const char* keyword); // 支持按名称/食材搜索 void list_all(); ``` #### 推荐扩展功能 1. **智能推荐系统** - 根据现有食材推荐谱(需实现食材匹配算法) - 示例逻辑: ```c void recommend_by_ingredients(char* available_ingredients) { // 分割用户输入的食材字符串 // 遍历谱数据库匹配重合度 // 输出匹配度最高的前N个谱 } ``` 2. **热量计算功能** - 为每道添加热量字段`float calories` - 实现每日摄入统计:`float calculate_daily_calories(int user_id)` 3. **用户账户系统** ```c typedef struct { int user_id; char username[30]; Recipe favorites[50]; // 收藏夹 } User; ``` 4. **数据可视化(进阶)** - 集成gnuplot生成烹饪时间分布图 - 导出HTML格式谱(通过C生成网页文件) 5. **移动端同步** - 添加网络模块(如libcurl)实现云端备份 - 设计简单的HTTP API:`/api/recipes?category=dessert` #### VSCode开发配置建议 1. **编译环境** - 在`.vscode/tasks.json`中配置C编译器: ```json "args": ["-Wall", "-Wextra", "main.c", "-o", "recipe_manager"] ``` - 启用调试配置(参考引用[1]中调试设置) 2. **项目结构** ``` /src main.c // 主逻辑 database.c // 文件存储操作 ui.c // 用户界面 /data recipes.dat // 谱数据库 ``` 3. **内存管理重点** - 使用动态内存分配时务必验证指针: ```c Recipe* r = malloc(sizeof(Recipe)); if(r == NULL) exit(EXIT_FAILURE); ``` - 文件操作后必须`fclose` #### 示例功能实现 ```c // 模糊搜索实现 void search_recipe(const char* keyword) { FILE* fp = fopen("recipes.dat", "rb"); Recipe temp; while(fread(&temp, sizeof(Recipe), 1, fp)) { if(strstr(temp.name, keyword) || strstr(temp.ingredients, keyword)) { print_recipe(temp); // 自定义打印函数 } } fclose(fp); } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值