电商系统之超管-管理员-商品(C语言)

2023-11-10 21:10

本文主要是介绍电商系统之超管-管理员-商品(C语言),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

大一暑假实训项目,主要对文件内容的增删改查,链表的基本应用。

编程小白,会的不多,只写了一些基本功能,函数大多是不带返回值的,避免错乱,简洁一些。

不过代码的健壮性还是不错滴。

代补功能:找回密码,各种信息独立修改。闲麻烦就没有打了OAO。

展示部分代码,如有错漏还望指正。


目录

文件存储格式

管理员 Administrator

超级管理员 SuperAdministrator

商品 MobilePhone

用户 Registering 

代码

提示注释和头文件及宏定义

结构体

函数原型

主函数

初始化超级管理员密码

超级管理员入口

管理员入口

注册管理员

注销管理员

修改管理员密码

查询用户

修改超级管理员密码

商品相关函数菜单

展示所有商品

添加商品

删除商品

修改商品价格

添加商品折扣

假二维码


文件存储格式

管理员 Administrator

依次:账号>密码>姓名>性别>电话号码


超级管理员 SuperAdministrator

依次:账号>密码,只有一个超级管理员。

 


商品 MobilePhone

依次:编号>品牌>价格>折扣>型号

 


用户 Registering 

依次:账号>密码>姓名>性别>电话号码>余额


代码

提示注释和头文件及宏定义

// fflush(stdin);
// 清空输入缓冲区// while((ch = getchar()) != '\n' && ch != EOF);
// 逐个读字符,遇到回车或者文本结尾为止
// 用于清空缓冲区// strspn(char * str_1, char * str_2)
// str_1 中的字符在 str_2 中, 则加 1
// 遇到第一个不在 str_2 中的字符, 则停止比较#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>  //便于生成随机数
#define SIZE 8    //定义数组大小
#define ch_1 "龖"  //用于生成仿二维码
#define ch_2 "  "  //二维码空白处
#define str "0123456789abcdefghijklmnopqrstuvwxyz"  //字母和数字

结构体

typedef struct superAdministrator  //超级管理员的结构体
{int account;  //超级管理员的账户 	int 6位数char password[SIZE*2];  //超级管理员的密码    int 9-15位数}SuperAdministrator;typedef struct administrtor  //管理员的结构体
{int account;  //管理员账号  6位char password[SIZE*2];  //密码  9-15位char name[SIZE];  //姓名char gender[SIZE];  //性别char telNum[SIZE*2];  //电话号码  11位struct administrtor * next;}Administrator;typedef struct mobile_phone  //手机的结构体
{int ID;  //编号  6位char type[SIZE];  //品牌  8位以内int price;  //价格double discount;  //折扣char name[SIZE*2];  //型号 小于16位struct mobile_phone * next;}MobilePhone;typedef struct customer  //顾客的结构体
{int account;  //顾客账号  6位char password[SIZE*2];  //密码  9-15位char name[SIZE];  //姓名char gender[SIZE];  //性别char telNum[SIZE*2];  //电话号码  11位int balance;  //用户余额struct customer * next;}customer;

函数原型

一共21个。

void Initial_super_administrator();  //初始化超级管理员
void loginSuperAdmin();  //超级管理员入口
void loginAdmin();  //管理员入口
void loginUser();  //用户入口
void createAdministrator();  //注册管理员
void removeAdministrator();  //注销管理员
void reviseAdministratorPassword();  //修改管理员密码
void SearrchCt();  //查询顾客
void changeSuAdminPassword();  //修改超级管理员密码
void relevant_Product();  //商品相关函数
void showInfo();  //展示所有商品信息
void addProduct();  //添加商品
void deleteProduct();  //删除商品
void reviseProduct();  //修改商品信息
void merchandiseDiscount();   //商品折扣
void input_error();  //输入错误显示
void file_open_error(FILE * fp);  //文件打开失败
void malloc_defeat(Administrator * A);  //动态内存申请失败
void admi_Destrong_List(Administrator * L);  //摧毁链表管理员
void prod_Destrong_List(MobilePhone * L);  //摧毁链表商品
void Payment_QR_code();  //支付二维码

主函数

int main()  //主函数
{Initial_super_administrator();  //初始化超级管理员while(1){char sel;  //选择char ch;  //用于清空缓冲区printf("||------------------------------------------||\n");printf("||     Welcome to Phone product system.     ||\n");printf("||------------------------------------------||\n");printf("||          【1】超级管理员登录             ||\n");printf("||          【2】管理员登录                 ||\n");printf("||          【0】退出                       ||\n");printf("||------------------------------------------||\n");printf("||   请选择: ");while((sel = getchar()) == '\n');  //不管输入什么都只读取第一个字符(除换行)while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区(清空第一个字符后的每一个字符)system("cls");  //清屏switch(sel){case '1':loginSuperAdmin();  //超级管理员入口break;case '2':loginAdmin();  //管理员入口break;case '0':printf("||------------------------------------------||\n");printf("||            系  统  已  关  闭            ||\n");printf("||------------------------------------------||\n");exit(0);default:input_error();  //输入错误显示}}return 0;
}

 


 

初始化超级管理员密码

主要是怕在某次测试中把密码忘了,每次都初始化,方便一些。不要也没关系。

void Initial_super_administrator()  //每次打开程序都会重新初始化超级管理员账号密码
{FILE * fp;const int account = 123456;  //常量避免值被修改const int password = 123456789;fp = fopen("SuperAdministrator.txt", "w");  //只写,无文件就创建文件file_open_error(fp);  //文件是否打开失败fprintf(fp, "%d\t%d\t", account, password);fclose(fp);  //关闭文件
}

超级管理员入口

void loginSuperAdmin()  //超级管理员入口
{char ch, sel;SuperAdministrator sa_1;  //超级管理员账号FILE * fp;  //文件指针int account;  //记录账号char password[SIZE*2];  //记录密码int len_1, len_2;  //记录密码个数, 记录密码合法字符个数while(1){while(1){printf("||------------------------------------------||\n");printf("||    输入 0 可取消登录, 请输入 6 位数字    ||\n");printf("||------------------------------------------||\n");printf("||  超级管理员账号:");scanf("%d", &account);system("cls");  //清屏if(account == 0)  //输入 0 返回上一级{return;}if(account<=100000 || account>999999)  //不是六位的数字{while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||      账号格式错误, 请输入 6 位数字       ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;  //账号格式正确}}while(1){printf("||------------------------------------------||\n");printf("||   输入 0 可取消登录, 9-15 位字母或数字   ||\n");printf("||------------------------------------------||\n");printf("||  超级管理员密码:");scanf("%s", password);system("cls");  //清屏if(strcmp(password, "0") == 0){return;}len_1 = strlen(password);len_2 = strspn(password, str);if(len_1<9 || len_1>15 || len_2<9 || len_2>15){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||     密码格式错误, 9-15 位字母或数字      ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;}}fp = fopen("SuperAdministrator.txt", "r");  //只读,避免修改file_open_error(fp);  //文件是否打开失败fscanf(fp, "%d\t%s\t", &sa_1.account, sa_1.password);if(account != sa_1.account || strcmp(password, sa_1.password) != 0)  //账号或密码错误{printf("||------------------------------------------||\n");printf("||       账号或密码错误, 请重新输入         ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏fclose(fp);continue;}printf("||------------------------------------------||\n");printf("||              登  陆  成  功              ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏while(1){printf("||------------------------------------------||\n");printf("||        超  级  管  理  员  菜  单        ||\n");printf("||------------------------------------------||\n");printf("||          【1】注册管理员                 ||\n");printf("||          【2】注销管理员                 ||\n");printf("||          【3】修改管理员密码             ||\n");printf("||          【4】查询顾客                   ||\n");printf("||          【5】修改密码                   ||\n");printf("||          【6】商品相关菜单               ||\n");printf("||          【0】退出登录                   ||\n");printf("||------------------------------------------||\n");printf("||   请选择: ");while((sel = getchar()) == '\n');  //不管输入什么都只读取第一个字符(除换行)while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区(清空第一个字符后的每一个字符)system("cls");  //清屏switch(sel){case '1':createAdministrator();  //添加管理员break;case '2':removeAdministrator();  //删除管理员break;case '3':reviseAdministratorPassword();  //修改管理员密码break;case '4':SearrchCt();  //查询顾客break;case '5':changeSuAdminPassword();  //修改超级管理员密码return;case '6':relevant_Product();  //商品相关函数break;case '0':fclose(fp);  //关闭文件return;  //返回上一级default:input_error();  //输入错误显示}}}
}

 


 

管理员入口

void loginAdmin()  //管理员入口
{char ch, sel;int flag = 0;  //记录是否查找成功Administrator a_1;  //管理员账号 a_1FILE * fp;  //文件指针int account;char password[SIZE*2];  //存储输入的账号密码int len_1, len_2;  //记录密码个数, 记录密码合法字符个数while(1){while(1){printf("||------------------------------------------||\n");printf("||    输入 0 可取消登录, 请输入 6 位数字    ||\n");printf("||------------------------------------------||\n");printf("||  管理员账号:");scanf("%d", &account);system("cls");  //清屏if(account == 0)  //输入 0 返回上一级{return;}if(account<=100000 || account>999999)  //不是六位的数字{while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||      账号格式错误, 请输入 6 位数字       ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;  //账号格式正确}}while(1){printf("||------------------------------------------||\n");printf("||   输入 0 可取消登录, 9-15 位字母或数字   ||\n");printf("||------------------------------------------||\n");printf("||  管理员密码:");scanf("%s", password);system("cls");  //清屏if(strcmp(password, "0") == 0){return;}len_1 = strlen(password);len_2 = strspn(password, str);if(len_1<9 || len_1>15 || len_2<9 || len_2>15){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||     密码格式错误, 9-15 位字母或数字      ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;}}fp = fopen("Administrator.txt", "r");  //打开文件file_open_error(fp);  //文件是否打开失败while(!feof(fp))  //文件指针到达末尾则返回 1{fscanf(fp, "%d\t%s\t%s\t%s\t%s\t\n", &a_1.account, a_1.password, a_1.name, a_1.gender, a_1.telNum);if(account == a_1.account && strcmp(password, a_1.password) == 0)  //账号密码都相同{flag = 1;  //登录成功break;}}if(flag == 0){printf("||------------------------------------------||\n");printf("||       账号或密码错误, 请重新输入         ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏fclose(fp);  //关闭文件continue;}printf("||------------------------------------------||\n");printf("||              登  陆  成  功              ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏while(1){printf("||------------------------------------------||\n");printf("||            管  理  员  菜  单            ||\n");printf("||------------------------------------------||\n");printf("||          【1】展示所有商品信息           ||\n");printf("||          【2】添加商品                   ||\n");printf("||          【3】删除商品                   ||\n");printf("||          【4】修改商品价格               ||\n");printf("||          【5】添加商品折扣               ||\n");printf("||          【6】查询顾客                   ||\n");printf("||          【0】退出登录                   ||\n");printf("||------------------------------------------||\n");printf("||   请选择: ");while((sel = getchar()) == '\n');  //不管输入什么都只读取第一个字符(除换行)while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区(清空第一个字符后的每一个字符)system("cls");  //清屏switch(sel){case '1':showInfo();  //展示所有商品信息system("pause");system("cls");break;case '2':addProduct();  //添加商品break;case '3':deleteProduct();  //删除商品break;case '4':reviseProduct();  //修改商品价格break;case '5':merchandiseDiscount();  //添加商品折扣break;case '6':SearrchCt();  //查询顾客break;case '0':fclose(fp);  //关闭文件return;  //返回上一级default:input_error();  //输入错误显示}}}
}

 


 

注册管理员

每次注册管理员,实际就是在文件末尾追加一个,账号用随机时生成,所以说,可能会出现账号相同的情况。

void createAdministrator()  //注册管理员
{srand((unsigned)time(NULL));  //种子库,成逐渐增大或逐渐减小char ch;Administrator a_1;  //管理员 a_1FILE * fp;int len_1, len_2;  //记录密码个数, 记录密码合法字符个数while(1){printf("||------------------------------------------||\n");printf("||     输入 0 可退出注册, 8 位以内字母      ||\n");printf("||------------------------------------------||\n");printf("||  管理员姓名: ");scanf("%s", a_1.name);system("cls");  //清屏if(strcmp(a_1.name, "0") == 0)  // 0 退出注册{return;}len_1 = strlen(a_1.name);if(len_1 < 8){break;}else{while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||       姓名格式不正确, 8 位以内字母       ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏}}while(1){printf("||------------------------------------------||\n");printf("||   输入 0 可退出注册, 请输入 11 位数字    ||\n");printf("||------------------------------------------||\n");printf("||  管理员手机号码: ");scanf("%s", a_1.telNum);system("cls");  //清屏if(strcmp(a_1.telNum, "0") == 0)  // 0 退出注册{return;}if(strspn(a_1.telNum, "0123456789") == 11){break;}else{while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||   手机号码格式不正确, 请输入 11 位数字   ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏}}while(1){printf("||------------------------------------------||\n");printf("||       输入 0 可退出注册, 男 或 女        ||\n");printf("||------------------------------------------||\n");printf("||  管理员性别: ");scanf("%s", a_1.gender);system("cls");  //清屏if(strcmp(a_1.gender, "0") == 0)  // 0 退出注册{return;}if(strcmp(a_1.gender, "男") == 0 || strcmp(a_1.gender, "女") == 0){break;}else{while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||      性别格式不正确, 请输入 男 或 女     ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏}}while(1){printf("||------------------------------------------||\n");printf("||   输入 0 可退出注册, 9-15 位字母或数字   ||\n");printf("||------------------------------------------||\n");printf("||   管理员密码:  ");scanf("%s", a_1.password);system("cls");  //清屏if(strcmp(a_1.password, "0") == 0){return;}len_1 = strlen(a_1.password);len_2 = strspn(a_1.password, str);if(len_1<9 || len_1>15 || len_2<9 || len_2>15){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||     密码格式错误, 9-15 位字母或数字      ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;}}a_1.account = 100000 + rand()%900000;fp = fopen("Administrator.txt", "a");  //只写,在末尾添加file_open_error(fp);  //文件是否打开失败fprintf(fp, "%d\t%s\t%s\t%s\t%s\t\n", a_1.account, a_1.password, a_1.name, a_1.gender, a_1.telNum);printf("||------------------------------------------||\n");printf("||             注  册  成  功               ||\n");printf("||------------------------------------------||\n");printf("|| 账号:%-8d  密码:%-16s   ||\n", a_1.account, a_1.password);printf("|| 姓名: %-8s  性别:%-4s               ||\n", a_1.name, a_1.gender);printf("|| 联系方式:%-16s               ||\n", a_1.telNum);printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏fclose(fp);
}

注销管理员

void removeAdministrator()  //注销管理员
{char ch;int i = 0;int account;int len_1, len_2;  //记录密码个数, 记录密码合法字符个数char password[SIZE*2];Administrator * A;  //管理员Administrator * tail;  //指向尾部的指针FILE * fp;  //文件指针while(1){printf("||------------------------------------------||\n");printf("||    输入 0 可退出注销, 请输入 6 位数字    ||\n");printf("||------------------------------------------||\n");printf("||   管理员账号:  ");scanf("%d", &account);system("cls");  //清屏if(account == 0){return;}if(account<=100000 || account>999999){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||      账号格式错误, 请输入 6 位数字       ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;}}while(1){printf("||------------------------------------------||\n");printf("||   输入 0 可退出注销, 9-15 位字母或数字   ||\n");printf("||------------------------------------------||\n");printf("||   管理员密码:  ");scanf("%s", password);system("cls");  //清屏if(strcmp(password, "0") == 0){return;}len_1 = strlen(password);len_2 = strspn(password, str);if(len_1<9 || len_1>15 || len_2<9 || len_2>15){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||     密码格式错误, 9-15 位字母或数字      ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;}}A = (Administrator *)malloc(sizeof(Administrator));  //申请动态内存malloc_defeat(A);  //内存是否申请失败A->next = NULL;tail = A;  //指向尾部的指针fp = fopen("Administrator.txt", "r");  //可读写,写时清除原本内容file_open_error(fp);  //文件是否打开失败while(!feof(fp))  //fp==EOF 返回 1{Administrator * p;  //存放数据的指针p = (Administrator *)malloc(sizeof(Administrator));  //申请动态内存malloc_defeat(p);  //内存是否申请失败fscanf(fp,"%d\t%s\t%s\t%s\t%s\t\n", &p->account, p->password, p->name, p->gender, p->telNum);if((account == p->account) && (strcmp(password, p->password) == 0)){i = 1;  //删除计为 1continue;  //如果信息相同,则不接入链表}tail->next = p;  //接到表尾tail = p;  //循环至表尾tail->next = NULL;  //表尾表尾赋空}printf("||------------------------------------------||\n");if(i){printf("||             删  除  成  功               ||\n");}else{printf("||       无该管理员或管理员信息错误         ||\n");}printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏fclose(fp);if(i == 0){admi_Destrong_List(A);  //摧毁链表return;}fp = fopen("Administrator.txt", "w");  //可读写,写时清除原本内容file_open_error(fp);  //文件是否打开失败tail = A->next;  //指向尾部的指针while(tail != NULL){fprintf(fp,"%d\t%s\t%s\t%s\t%s\t\n", tail->account, tail->password, tail->name, tail->gender, tail->telNum);tail = tail->next;  //继续写入下一个}admi_Destrong_List(A);  //摧毁链表fclose(fp);  //关闭文件
}

修改管理员密码

修改密码都要双重认证新密码是否相同。

void reviseAdministratorPassword()  //修改管理员密码
{char ch;int i = 0;int account;int len_1, len_2;  //记录密码个数, 记录密码合法字符个数char password[SIZE*2];char password_1[SIZE*2], password_2[SIZE*2];FILE * fp;  //文件指针Administrator * A;  //管理员Administrator * tail;  //指向尾部的指针while(1){printf("||------------------------------------------||\n");printf("||   输入 0 即可取消修改, 请输入 6 位数字   ||\n");printf("||------------------------------------------||\n");printf("||   管理员账号:  ");scanf("%d", &account);system("cls");  //清屏if(account == 0){return;}if(account<=100000 || account>999999){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||      账号格式错误, 请输入 6 位数字       ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;}}while(1){printf("||------------------------------------------||\n");printf("||   输入 0 可取消修改, 9-15 位字母或数字   ||\n");printf("||------------------------------------------||\n");printf("||   管理员密码:  ");scanf("%s", password);system("cls");  //清屏if(strcmp(password, "0") == 0){return;}len_1 = strlen(password);len_2 = strspn(password, str);if(len_1<9 || len_1>15 || len_2<9 || len_2>15){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||     密码格式错误, 9-15 位字母或数字      ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;}}fp = fopen("Administrator.txt", "r");  //可读写file_open_error(fp);  //文件是否打开失败A = (Administrator *)malloc(sizeof(Administrator));  //申请动态内存malloc_defeat(A);  //内存是否申请失败A->next = NULL;tail = A;  //指向尾部的指针while(!feof(fp))  //fp==EOF 返回 1{Administrator * p;  //存放数据的指针p = (Administrator *)malloc(sizeof(Administrator));  //申请动态内存malloc_defeat(p);  //内存是否申请失败fscanf(fp, "%d\t%s\t%s\t%s\t%s\t\n", &p->account, p->password, p->name, p->gender, p->telNum);while((account == p->account)&&(strcmp(password, p->password) == 0))  //账号密码相同{while(1){printf("||------------------------------------------||\n");printf("||   输入 0 可取消修改, 9-15 位字母或数字   ||\n");printf("||------------------------------------------||\n");printf("||   新密码:  ");scanf("%s", password_1);system("cls");  //清屏if(strcmp(password_1, "0") == 0){return;}len_1 = strlen(password_1);len_2 = strspn(password_1, str);if(len_1<9 || len_1>15 || len_2<9 || len_2>15){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||    新密码格式错误, 9-15 位字母或数字     ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;}}while(1){printf("||------------------------------------------||\n");printf("||   输入 0 可取消修改, 9-15 位字母或数字   ||\n");printf("||------------------------------------------||\n");printf("||   请再次输入新密码: ");scanf("%s", password_2);system("cls");  //清屏if(strcmp(password_2, "0") == 0){return;}len_1 = strlen(password_2);len_2 = strspn(password_2, str);if(len_1<9 || len_1>15 || len_2<9 || len_2>15){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||    新密码格式错误, 9-15 位字母或数字     ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;}}if(strcmp(password_1, password_2) == 0){i = 1;strcpy(p->password, password_2);}else{printf("||------------------------------------------||\n");printf("||            密  码  不  相  同            ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏}}tail->next = p;  //接到表尾tail = p;  //循环至表尾tail->next = NULL;  //表尾表尾赋空}printf("||------------------------------------------||\n");if(i){printf("||             修  改  成  功               ||\n");}else{printf("||       无该管理员或管理员信息错误         ||\n");}printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏fclose(fp);if(i == 0){admi_Destrong_List(A);  //摧毁链表return;}fp = fopen("Administrator.txt", "w");  //可读写,写时清除原本内容file_open_error(fp);  //文件是否打开失败tail = A->next;  //指向尾部的指针while(tail != NULL){fprintf(fp,"%d\t%s\t%s\t%s\t%s\t\n", tail->account, tail->password, tail->name, tail->gender, tail->telNum);tail = tail->next;  //继续写入下一个}admi_Destrong_List(A);  //摧毁链表fclose(fp);  //释放文件指针
}

查询用户

根据用户姓名进行查询。目前只能用姓名,闲麻烦没有搞别的。

void SearrchCt()  //查询顾客
{customer u_1;  //顾客FILE * fp;char name[SIZE];fp = fopen("Registering.txt", "r");  //可读写file_open_error(fp);  //文件是否打开失败printf("||------------------------------------------||\n");printf("||   顾客姓名:  ");scanf("%s", name);system("cls");  //清屏while(!feof(fp))  //fp==EOF 返回 1{fscanf(fp,"%d\t%s\t%s\t%s\t%s\t%d\t\n",&u_1.account, u_1.password,u_1.name,u_1.gender,u_1.telNum, &u_1.balance);if(strcmp(name, u_1.name) == 0){printf("||------------------------------------------||\n");printf("|| 账号:%-8d  密码:%-16s   ||\n", u_1.account, u_1.password);printf("|| 姓名:%-8s  联系方式:%-11s    ||\n", u_1.name, u_1.telNum);printf("|| 性别:%-4s      余额:%-12d       ||\n", u_1.gender, u_1.balance);printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏fclose(fp);  //关闭文件return;}}printf("||------------------------------------------||\n");printf("||             无  此  顾  客               ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏fclose(fp);  //关闭文件
}

 


 

修改超级管理员密码

和修改管理员密码思路基本一致。

void changeSuAdminPassword()  //修改超级管理员密码
{char ch;char password_1[SIZE*2], password_2[SIZE*2];int len_1, len_2;  //记录密码个数, 记录密码合法字符个数SuperAdministrator sa_1;FILE * fp;fp = fopen("SuperAdministrator.txt", "r+");  //可读写,写时清除原本内容file_open_error(fp);  //文件是否打开失败fscanf(fp, "%d\t%s\t", &sa_1.account, sa_1.password);while(1){while(1){printf("||------------------------------------------||\n");printf("||   输入 0 可取消修改, 9-15 位字母或数字   ||\n");printf("||------------------------------------------||\n");printf("||   新密码:  ");scanf("%s", password_1);system("cls");  //清屏if(strcmp(password_1, "0") == 0){return;}len_1 = strlen(password_1);len_2 = strspn(password_1, str);if(len_1<9 || len_1>15 || len_2<9 || len_2>15){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||    新密码格式错误, 9-15 位字母或数字     ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;}}while(1){printf("||------------------------------------------||\n");printf("||   输入 0 可取消修改, 9-15 位字母或数字   ||\n");printf("||------------------------------------------||\n");printf("||   请再次输入新密码: ");scanf("%s", password_2);system("cls");  //清屏if(strcmp(password_2, "0") == 0){return;}len_1 = strlen(password_2);len_2 = strspn(password_2, str);if(len_1<9 || len_1>15 || len_2<9|| len_2>15){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||    新密码格式错误, 9-15 位字母或数字     ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;}}if(strcmp(password_1, password_2) == 0){strcpy(sa_1.password, password_2);fseek(fp, 0, SEEK_SET);fprintf(fp,"%d\t%s\t", sa_1.account, sa_1.password);printf("||------------------------------------------||\n");printf("||        修 改 成 功, 请 重 新 登 录       ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏break;}else{printf("||------------------------------------------||\n");printf("||            密  码  不  相  同            ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏}}fclose(fp);
}

商品相关函数菜单

就是选择对商品的操作。功能有点少了。

void relevant_Product()  //商品相关函数
{char ch, sel;while(1){printf("||------------------------------------------||\n");printf("||          商  品  相  关  菜  单          ||\n");printf("||------------------------------------------||\n");printf("||           【1】所有商品                  ||\n");printf("||           【2】添加商品                  ||\n");printf("||           【3】删除商品                  ||\n");printf("||           【4】修改商品价格              ||\n");printf("||           【5】添加商品折扣              ||\n");printf("||           【0】返回                      ||\n");printf("||------------------------------------------||\n");printf("||   请选择: ");while((sel = getchar()) == '\n');  //不管输入什么都只读取第一个字符(除换行)while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区(清空第一个字符后的每一个字符)system("cls");  //清屏switch(sel){case '1':showInfo();  //展示所有商品信息system("pause");system("cls");break;case '2':addProduct();  //添加商品break;case '3':deleteProduct();  //删除商品break;case '4':reviseProduct();  //修改商品价格break;case '5':merchandiseDiscount();  //添加商品折扣break;case '0':return;  //返回上一级default:input_error();  //输入错误显示}}
}

 


 

展示所有商品

void showInfo()  //展示所有商品信息
{FILE * fp;  //文件指针MobilePhone mp_1;fp = fopen("MobilePhone.txt", "r");  //只读,避免被修改file_open_error(fp);  //文件是否打开失败printf("||------------------------------------------||\n");printf("|| 编号      型号               价格    折扣||\n");while(!feof(fp)){fscanf(fp,"%d\t%s\t%d\t%lf\t%s\t\n", &mp_1.ID, mp_1.type, &mp_1.price, &mp_1.discount, mp_1.name);  //中转站printf("||%-8d%-7s%-15s%-8d%.2lf||\n", mp_1.ID, mp_1.type, mp_1.name, mp_1.price, mp_1.discount);}printf("||------------------------------------------||\n");fclose(fp);
}

 


 

添加商品

和注册管理员相似。

void addProduct()  //添加商品
{int len;char ch;FILE * fp;MobilePhone mp_1;while(1){printf("||------------------------------------------||\n");printf("||    输入 0 可取消添加, 请输入 6 位数字    ||\n");printf("||------------------------------------------||\n");printf("||    商品编号: ");scanf("%d", &mp_1.ID);system("cls");  //清屏if(mp_1.ID == 0)  //输入 0 返回上一级{return;}if(mp_1.ID<=100000 || mp_1.ID>999999)  //不是六位的数字{while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||      编号格式错误, 请输入 6 位数字       ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;  //账号格式正确}}while(1){printf("||------------------------------------------||\n");printf("||     输入 0 可取消添加, 8 位以内字母      ||\n");printf("||------------------------------------------||\n");printf("||     商品品牌: ");scanf("%s", mp_1.type);system("cls");  //清屏if(strcmp(mp_1.type, "0") == 0)  //输入 0 返回上一级{return;}len = strlen(mp_1.type);if(len >= 8){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||        品牌格式错误, 8 位以内字母        ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;  //账号格式正确}}printf("||------------------------------------------||\n");printf("||    商品型号:  ");scanf("%s", mp_1.name);system("cls");  //清屏printf("||------------------------------------------||\n");printf("||    商品价格:  ");scanf("%d", &mp_1.price);system("cls");  //清屏mp_1.discount = 1.0;fp = fopen("MobilePhone.txt", "a");  //只写,追加file_open_error(fp);  //文件是否打开失败fprintf(fp,"%d\t%s\t%d\t%lf\t%s\t\n", mp_1.ID, mp_1.type, mp_1.price, mp_1.discount, mp_1.name);printf("||------------------------------------------||\n");printf("||             添  加  成  功               ||\n");printf("||------------------------------------------||\n");printf("|| 编号      型号               价格    折扣||\n");printf("||%-8d%-7s%-15s%-8d%.2lf||\n", mp_1.ID, mp_1.type, mp_1.name, mp_1.price, mp_1.discount);printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏fclose(fp);
}

删除商品

void deleteProduct()  //删除商品
{char ch;int i = 0;int ID;MobilePhone * MP;  //商品MobilePhone * tail;  //指向尾部的指针FILE * fp;  //文件指针MP = (MobilePhone *)malloc(sizeof(MobilePhone));  //申请动态内存if(MP == NULL){printf("||------------------------------------------||\n");printf("||          内  存  申  请  失  败          ||\n");printf("||------------------------------------------||\n");exit(0);}MP->next = NULL;tail = MP;  //指向尾部的指针fp = fopen("MobilePhone.txt", "r");  //可读写,写时清除原本内容file_open_error(fp);  //文件是否打开失败while(1){printf("||------------------------------------------||\n");printf("||    输入 0 可取消删除, 请输入 6 位数字    ||\n");printf("||------------------------------------------||\n");printf("||    商品编号: ");scanf("%d", &ID);system("cls");  //清屏if(ID == 0)  //输入 0 返回上一级{return;}if(ID<=100000 || ID>999999)  //不是六位的数字{while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||      编号格式错误, 请输入 6 位数字       ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;  //账号格式正确}}while(!feof(fp))  //fp==EOF 返回 1{MobilePhone * p;  //存放数据的指针p = (MobilePhone *)malloc(sizeof(MobilePhone));  //申请动态内存if(p == NULL){printf("||------------------------------------------||\n");printf("||          内  存  申  请  失  败          ||\n");printf("||------------------------------------------||\n");exit(0);}fscanf(fp,"%d\t%s\t%d\t%lf\t%s\t\n",&p->ID,p->type,&p->price,&p->discount,p->name);if(ID == p->ID){i = 1;  //删除计为 1continue;  //如果信息相同,则不接入链表}tail->next = p;  //接到表尾tail = p;  //循环至表尾tail->next = NULL;  //表尾表尾赋空}printf("||------------------------------------------||\n");if(i){printf("||             删  除  成  功               ||\n");}else{printf("||         无该商品或商品编号错误           ||\n");}printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏fclose(fp);if(i == 0)  //摧毁指针,并且返回{prod_Destrong_List(MP);  //销毁链表return;}fp = fopen("MobilePhone.txt", "w");  //可读写,写时清除原本内容file_open_error(fp);  //文件是否打开失败tail = MP->next;  //指向尾部的指针while(tail != NULL){fprintf(fp,"%d\t%s\t%d\t%lf\t%s\t\n", tail->ID, tail->type, tail->price, tail->discount, tail->name);tail = tail->next;  //继续写入下一个}prod_Destrong_List(MP);  //销毁链表fclose(fp);  //释放文件指针
}

修改商品价格

void reviseProduct()  //修改商品价格
{char ch;int i = 0;int ID;MobilePhone * MP;  //商品MobilePhone * tail;  //指向尾部的指针FILE * fp;  //文件指针MP = (MobilePhone *)malloc(sizeof(MobilePhone));  //申请动态内存if(MP == NULL){printf("||------------------------------------------||\n");printf("||          内  存  申  请  失  败          ||\n");printf("||------------------------------------------||\n");exit(0);}MP->next = NULL;tail = MP;  //指向尾部的指针while(1){printf("||------------------------------------------||\n");printf("||    输入 0 可取消修改, 请输入 6 位数字    ||\n");printf("||------------------------------------------||\n");printf("||    需改商品编号:");scanf("%d", &ID);system("cls");  //清屏if(ID == 0)  //输入 0 返回上一级{return;}if(ID<=100000 || ID>999999)  //不是六位的数字{while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||      编号格式错误, 请输入 6 位数字       ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;  //账号格式正确}}fp = fopen("MobilePhone.txt", "r");  //可读写file_open_error(fp);  //文件是否打开失败while(!feof(fp))  //fp==EOF 返回 1{MobilePhone * p;  //存放数据的指针p = (MobilePhone *)malloc(sizeof(MobilePhone));  //申请动态内存if(p == NULL){printf("||------------------------------------------||\n");printf("||          内  存  申  请  失  败          ||\n");printf("||------------------------------------------||\n");exit(0);}fscanf(fp,"%d\t%s\t%d\t%lf\t%s\t\n",&p->ID,p->type,&p->price,&p->discount,p->name);if(ID == p->ID)  //编号相同{printf("||------------------------------------------||\n");printf("||            修  改  后  价  格            ||\n");printf("||------------------------------------------||\n");printf("||    商品价格: ");scanf("%d", &p->price);system("cls");  //清屏i = 1;}tail->next = p;  //接到表尾tail = p;  //循环至表尾tail->next = NULL;  //表尾表尾赋空}printf("||------------------------------------------||\n");if(i){printf("||             修  改  成  功               ||\n");}else{printf("||         无该商品或商品编号错误           ||\n");}printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏fclose(fp);  //关闭文件if(i == 0)  //销毁链表,并且返回{prod_Destrong_List(MP);return;}fp = fopen("MobilePhone.txt", "w");  //可读写,写时清除原本内容file_open_error(fp);  //文件是否打开失败tail = MP->next;  //指向尾部的指针while(tail != NULL){fprintf(fp, "%d\t%s\t%d\t%lf\t%s\t\n", tail->ID, tail->type, tail->price, tail->discount, tail->name);tail = tail->next;  //继续写入下一个}prod_Destrong_List(MP);  //销毁链表fclose(fp);  //释放文件指针
}

添加商品折扣

用小数代替,相当于1是不打折,0.9是9折,以此类推。

void merchandiseDiscount()   //添加商品折扣
{char ch;int i = 0;int ID;MobilePhone * MP;  //商品MobilePhone * tail;  //指向尾部的指针FILE * fp;  //文件指针MP = (MobilePhone *)malloc(sizeof(MobilePhone));  //申请动态内存if(MP == NULL){printf("||------------------------------------------||\n");printf("||         内  存  申  请  失  败           ||\n");printf("||------------------------------------------||\n");exit(0);}MP->next = NULL;tail = MP;  //指向尾部的指针fp = fopen("MobilePhone.txt", "r");  //可读写file_open_error(fp);  //文件是否打开失败while(1){printf("||------------------------------------------||\n");printf("||    输入 0 可取消添加, 请输入 6 位数字    ||\n");printf("||------------------------------------------||\n");printf("||    商品编号: ");scanf("%d", &ID);system("cls");  //清屏if(ID == 0)  //输入 0 返回上一级{return;}if(ID<=100000 || ID>999999)  //不是六位的数字{while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区printf("||------------------------------------------||\n");printf("||      编号格式错误, 请输入 6 位数字       ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;  //账号格式正确}}while(!feof(fp))  //fp==EOF 返回 1{MobilePhone * p;  //存放数据的指针p = (MobilePhone *)malloc(sizeof(MobilePhone));  //申请动态内存if(p == NULL){printf("||------------------------------------------||\n");printf("||          内  存  申  请  失  败          ||\n");printf("||------------------------------------------||\n");exit(0);}fscanf(fp,"%d\t%s\t%d\t%lf\t%s\t\n",&p->ID,p->type,&p->price,&p->discount,p->name);if(ID == p->ID)  //编号相同{while(1){printf("||------------------------------------------||\n");printf("||        添 加 折 扣, 小 数(例: 0.9)       ||\n");printf("||------------------------------------------||\n");printf("||      折扣:  ");scanf("%lf", &p->discount);system("cls");  //清屏if(p->discount<=0 || p->discount>1){while((ch = getchar()) != '\n' && ch != EOF);  //清空缓冲区(清空第一个字符后的每一个字符)printf("||------------------------------------------||\n");printf("||    折扣格式错误, 请输入小于 1 的小数     ||\n");printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏continue;}else{break;}}i = 1;  //添加成功}tail->next = p;  //接到表尾tail = p;  //循环至表尾tail->next = NULL;  //表尾表尾赋空}printf("||------------------------------------------||\n");if(i){printf("||             添  加  成  功               ||\n");}else{printf("||         无该商品或商品编号错误           ||\n");}printf("||------------------------------------------||\n");system("pause");  //暂停system("cls");  //清屏fclose(fp);  //关闭文件if(i == 0)  //销毁链表,并且返回{prod_Destrong_List(MP);return;}fp = fopen("MobilePhone.txt", "w");  //可读写,写时清除原本内容file_open_error(fp);  //文件是否打开失败tail = MP->next;  //指向尾部的指针while(tail != NULL){fprintf(fp,"%d\t%s\t%d\t%lf\t%s\t\n", tail->ID, tail->type, tail->price, tail->discount, tail->name);tail = tail->next;  //继续写入下一个}prod_Destrong_List(MP);  //销毁链表fclose(fp);  //释放文件指针
}

假二维码

其实这个二维码只是一个用循环结合if语句一个格子一个格子的打印出来的图像,利用随机数,除了固定位置,其余位置每次打印都会不一样。

所以说,是扫不出来的哦。

不过这个函数在这个项目里面没有调用,原本是购买商品时的支付二维码和余额充值的支付二维码,属于是对用户的操作了,就没有调用。感兴趣的小伙伴可以复制打印一下。

void Payment_QR_code()  //支付二维码
{const int n = 25;int i, j;srand((unsigned)time(NULL));  //种子库,成逐渐增大或逐渐减小for(i = 1; i <= n; i++){for(j = 1; j <= n; j++){//定黑if((i==1&&j<=7)||(i==1&&j>=n-6)||(i==7&&j<=7)||(i==7&&j>=n-6)){printf(ch_1);continue;}if((j==1&&i<=7)||(j==1&&i>=n-6)||(j==7&&i<=7)||(j==7&&i>=n-6)){printf(ch_1);continue;}if(((i==n-6||i==n)&&j<=7)||((j==n-6||j==n)&&i<=7)){printf(ch_1);continue;}if((i==3||i==4||i==5||i==n-2||i==n-3||i==n-4)&&(j==3||j==4||j==5)){printf(ch_1);continue;}if((i==3||i==4||i==5)&&(j==3||j==4||j==5||j==n-2||j==n-3||j==n-4)){printf(ch_1);continue;}if((i==n-4||i==n-8)&&(j<=n-4&&j>=n-8)){printf(ch_1);continue;}if((j==n-4||j==n-8)&&(i<=n-4&&i>=n-8)){printf(ch_1);continue;}if(i==n-6&&j==n-6){printf(ch_1);continue;}//定白if(i==2&&((j>=2&&j<=6)||(j<=n-1&&j>=n-5))){printf(ch_2);continue;}if(i==6&&((j>=2&&j<=6)||(j<=n-1&&j>=n-5))){printf(ch_2);continue;}if(j==2&&((i>=2&&i<=6)||(i<=n-1&&i>=n-5))){printf(ch_2);continue;}if(j==6&&((i>=2&&i<=6)||(i<=n-1&&i>=n-5))){printf(ch_2);continue;}if(i==8&&(j<=8||j>=n-7)){printf(ch_2);continue;}if(j==8&&(i<=8||i>=n-7)){printf(ch_2);continue;}if(i==n-7&&((j<=8)||(j<=n-5&&j>=n-7))){printf(ch_2);continue;}if(j==n-7&&((i<=8)||(i<=n-5&&i>=n-7))){printf(ch_2);continue;}if(i==n-5&&((j<=8)||(j<=n-5&&j>=n-7))){printf(ch_2);continue;}if(j==n-5&&((i<=8)||(i<=n-5&&i>=n-7))){printf(ch_2);continue;}if(i==n-1&&(j<=6&&j>=2)){printf(ch_2);continue;}if(j==n-1&&(i<=6&&i>=2)){printf(ch_2);continue;}else  //随机{if(rand()%2){printf(ch_1);continue;}else{printf(ch_2);continue;}}}printf("\n");}system("pause");  //暂停system("cls");  //清屏
}

 


给个赞吧OAO,谢谢!

完结......

这篇关于电商系统之超管-管理员-商品(C语言)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/385262

相关文章

Three.js构建一个 3D 商品展示空间完整实战项目

《Three.js构建一个3D商品展示空间完整实战项目》Three.js是一个强大的JavaScript库,专用于在Web浏览器中创建3D图形,:本文主要介绍Three.js构建一个3D商品展... 目录引言项目核心技术1. 项目架构与资源组织2. 多模型切换、交互热点绑定3. 移动端适配与帧率优化4. 可

JWT + 拦截器实现无状态登录系统

《JWT+拦截器实现无状态登录系统》JWT(JSONWebToken)提供了一种无状态的解决方案:用户登录后,服务器返回一个Token,后续请求携带该Token即可完成身份验证,无需服务器存储会话... 目录✅ 引言 一、JWT 是什么? 二、技术选型 三、项目结构 四、核心代码实现4.1 添加依赖(pom

GO语言短变量声明的实现示例

《GO语言短变量声明的实现示例》在Go语言中,短变量声明是一种简洁的变量声明方式,使用:=运算符,可以自动推断变量类型,下面就来具体介绍一下如何使用,感兴趣的可以了解一下... 目录基本语法功能特点与var的区别适用场景注意事项基本语法variableName := value功能特点1、自动类型推

GO语言中函数命名返回值的使用

《GO语言中函数命名返回值的使用》在Go语言中,函数可以为其返回值指定名称,这被称为命名返回值或命名返回参数,这种特性可以使代码更清晰,特别是在返回多个值时,感兴趣的可以了解一下... 目录基本语法函数命名返回特点代码示例命名特点基本语法func functionName(parameters) (nam

基于Python实现自动化邮件发送系统的完整指南

《基于Python实现自动化邮件发送系统的完整指南》在现代软件开发和自动化流程中,邮件通知是一个常见且实用的功能,无论是用于发送报告、告警信息还是用户提醒,通过Python实现自动化的邮件发送功能都能... 目录一、前言:二、项目概述三、配置文件 `.env` 解析四、代码结构解析1. 导入模块2. 加载环

linux系统上安装JDK8全过程

《linux系统上安装JDK8全过程》文章介绍安装JDK的必要性及Linux下JDK8的安装步骤,包括卸载旧版本、下载解压、配置环境变量等,强调开发需JDK,运行可选JRE,现JDK已集成JRE... 目录为什么要安装jdk?1.查看linux系统是否有自带的jdk:2.下载jdk压缩包2.解压3.配置环境

Go语言连接MySQL数据库执行基本的增删改查

《Go语言连接MySQL数据库执行基本的增删改查》在后端开发中,MySQL是最常用的关系型数据库之一,本文主要为大家详细介绍了如何使用Go连接MySQL数据库并执行基本的增删改查吧... 目录Go语言连接mysql数据库准备工作安装 MySQL 驱动代码实现运行结果注意事项Go语言执行基本的增删改查准备工作

Go语言使用Gin处理路由参数和查询参数

《Go语言使用Gin处理路由参数和查询参数》在WebAPI开发中,处理路由参数(PathParameter)和查询参数(QueryParameter)是非常常见的需求,下面我们就来看看Go语言... 目录一、路由参数 vs 查询参数二、Gin 获取路由参数和查询参数三、示例代码四、运行与测试1. 测试编程路

Go语言使用net/http构建一个RESTful API的示例代码

《Go语言使用net/http构建一个RESTfulAPI的示例代码》Go的标准库net/http提供了构建Web服务所需的强大功能,虽然众多第三方框架(如Gin、Echo)已经封装了很多功能,但... 目录引言一、什么是 RESTful API?二、实战目标:用户信息管理 API三、代码实现1. 用户数据

Linux查询服务器系统版本号的多种方法

《Linux查询服务器系统版本号的多种方法》在Linux系统管理和维护工作中,了解当前操作系统的版本信息是最基础也是最重要的操作之一,系统版本不仅关系到软件兼容性、安全更新策略,还直接影响到故障排查和... 目录一、引言:系统版本查询的重要性二、基础命令解析:cat /etc/Centos-release详