当前位置:网站首页>C language course design (detailed explanation of clothing management system)
C language course design (detailed explanation of clothing management system)
2022-06-21 05:58:00 【Xiao Hou doesn't lie flat】
I was working on last week and next week C Curriculum design of language , So updating new knowledge is a little slow , This blog will lead you to an in-depth understanding of c The operation of language files and the problems I encountered when writing code .
First, I set up the user login system 、 The administrator logs in to the system . After logging in to the system, the user will compare the size of the clothes filled in by the user with the rest in the clothing system, so as to recommend the clothes that meet her size to the user .
Implementation of this code , It may be because I have been clumsy for a long time and have been using it in reading files fwrite and fread. So I can't read the information in the clothing text to the correct position, so I keep thinking about why it read All the information will be read into the first character array of the structure , Then I found out in the course design that read This function reads one line of information , There is no way to store and read information one by one , So I'm going to put all of the fwrite and fread Change to fprintf and fscanf. After compiling, it is found that the user will normally recommend clothing information after logging in . This is my own thinking , Then it is found that it can only recommend one clothing type after output , But I also used it feof To determine if it's at the end, so I use a loop . I found that I couldn't get out of the recycling , And in if The loop doesn't know how to get out after judging equality in , So I listened to my friend's advice and used a counter , First count the whole , Then the next cycle will exit after the total number of clothes . But another problem is that after reading the file, the pointer points to the end of the file , So we have to use fseek() The function causes the pointer to point back to the beginning of the file in the garment text , Read it again . In fact, I think the function can also use the linked list, but I have a lot of code and functions. If I use the linked list, it will be very messy , And hard to find bug So I chose the counter method . After the lesson design, I will try to use the linked list to analyze its functions .
The code of this module is as follows :
void userin()
{
Users y={0};
stu f={0};
int count=0;
FILE *pe=fopen("users.txt","r+");
FILE *pi=fopen("fuzhuang.txt","r+");
fscanf(pe,"%s %s %s %s %s",y.id,y.name,y.paw,y.sex,y.size);
fscanf(pi,"%s %s %s %s %d %d",&f.brand,&f.name,&f.num,&f.size,&f.price,&f.stock);
printf("\t The same size clothes as yours are still in stock :\n");
printf("\t Clothing brand \t Clothing number \t Clothing type \t Clothing size \t Clothing prices \t Clothing inventory \n");
while(1)
{
if(feof(pi)==0)
{
fscanf(pi,"%s %s %s %s %d %d",&f.brand,&f.name,&f.num,&f.size,&f.price,&f.stock);
count++;
}
else
break;
}
fseek(pi,0L,SEEK_SET);
while(count--)
{
if(strcmp(y.size,f.size)!=0)
{
if(feof(pi)==0)
{
fscanf(pi,"%s %s %s %s %d %d",&f.brand,&f.name,&f.num,&f.size,&f.price,&f.stock);
}
}
else
{
printf("\t%s\t\t%s\t\t%s\t\t%s\t\t%d\t\t%d\n",f.brand,f.num,f.name,f.size,f.price,f.stock);
if(feof(pi)==0)
{
fscanf(pi,"%s %s %s %s %d %d",&f.brand,&f.name,&f.num,&f.size,&f.price,&f.stock);
}
}
}
} Of course, in addition to this function, I think the implementation of another function is a little difficult , For example, the data to be saved and the data to be read during user registration and login . And compare them for equality , The realization of the two functions is not bad , So let's go straight to the registration and login code !
void Regist()
{
administrator a={0},b={0};
char tmp[20]={-1}; // Used to determine whether the passwords are the same
FILE *pf = NULL;
pf = fopen("administrator.txt","r"); // use pf To point to a file , A file is a file that already exists read only mode
if(pf == NULL)
{
printf(" Failed to open file during registration \n");
return ;
}
printf("\t\t\t Welcome to the registration screen \n\n");
printf("\t\t\t Enter account ->");
scanf("%s",a.id);
printf(" Input successful !\n");
//【 The registration screen 】
printf("\t\t\t Please enter a name ->");
scanf("%s",a.name);
printf("\t\t\t Please enter gender : male / Woman ->");
do
{ // Enter the gender and see if it is correct
getchar();
scanf("%s",a.sex);
}while(1);
printf("\t\t\t Please input a password ->");
scanf("%s",a.paw);
printf("\t\t\t Please enter the password again ->");
do // Determine whether the two passwords are equal
{
scanf("%s",tmp);
if(strcmp(tmp,a.paw) != 0)
printf("\t\t\t The two passwords are not the same , Please enter the password again ->");
else
break;
}while(1);
// The two passwords are the same
fclose(pf);
pf = NULL;
pf = fopen("administrator.txt","a"); // Write file as append
//fwrite Writes data at the position of the current file pointer
//"w" open , The file pointer goes to the head , Just write ;"a" open , Point to the end of the file , No coverage .
fprintf(pf,"%s %s %s %s",a.name,a.paw,a.id,a.sex); // take a The data is stored in the file
printf("\t\t\t Registered successfully !\n");
fclose(pf);
pf = NULL;
system("cls");
return;
}
bool Login() // The return value is a boolean variable
{
administrator a={0},b={0};
FILE *pf = fopen("administrator.txt","r+"); // Open the file in read mode
if(pf == NULL)
{
printf(" File opening failure \n");
return false;
}
printf(" Welcome to the login screen !\n");
printf(" Please enter your account number ->");
scanf("%s",a.id);
fscanf(pf,"%s %s %s %s",b.name,b.paw,b.id,b.sex); // Each read Users Length , Read it once .
while(1)
{
if(strcmp(a.id, b.id) != 0 )
{
if(feof(pf) == 0)// Not to the end of the file Always look back
{
fscanf(pf,"%s %s %s %s",b.name,b.paw,b.id,b.sex);
}
else
{
printf(" The account does not exist , Please register first \n");
fclose(pf);
pf = NULL;
return false;
}
}
else// The account has been registered -> Skip to enter password
{
break; // Exit infinite loop , Skip to enter password
}
}
//【 Input password 】
printf(" Please input a password ->");
do
{
scanf("%s",a.paw);
}while(1);
printf(" Login successful !\n");
fclose(pf);
pf = NULL;
system("cls");
return true;
}In order to prevent you from copying and pasting the code directly, I have made some cuts to the above code , If you need to set up relevant functions of the class, you can csdn Send me a private letter , I will certainly answer the question .
I personally think the implementation of other codes is very simple, so I won't introduce other codes in detail here . I will take a screenshot of my program , You can have a look. If you need any function, you can send me a private message .

My user login may add many functions later .
The following figure shows how to recommend the price the user wants :

The following are the related operations for exiting the system :

This is the end of my blog , If you want the code for some of the functions here, you can confide in me , Or my blog has some unclear language or ideas , Welcome to help me point out thank you !
边栏推荐
- SSH copy ID batch - free script
- Arm authoritative guide and our group's project notes
- sqli-labs26
- These classic software, which was once very popular, are still fresh in my memory now
- JS encapsulates functions, and the results are appended after multiple calls
- Importance of variables in code
- Research and Analysis on the current situation of China's Internet of things microcontroller market and forecast report on its development prospect (2022)
- [UVM basics] three commonly used phase functions: build_ phase/connect_ phase/run_ phase
- 复制 代码生成器 生成的代码到idea中,运行后网址报错怎么解决
- El table circular upgrade
猜你喜欢

应用在洗衣机触摸屏中的触摸芯片
![[grafana] optimization of grafana MIMIR in massive time series indicators](/img/02/e4ec6598e43f0fe111614eb26fe196.png)
[grafana] optimization of grafana MIMIR in massive time series indicators

Librosa 𞓜 the most humorous explanation of Mel spectrum

JS encapsulates functions, and the results are appended after multiple calls

kali快捷键和设置方式

Canvas makes classic Snake

simple_js 攻防世界

sqli-labs-17

硬件探索——数字钟的设计与制作
![[SQL injection 16] read / write file for SQL vulnerability exploitation](/img/83/1c4680d4ea6980e0777b8ea4eeaba5.jpg)
[SQL injection 16] read / write file for SQL vulnerability exploitation
随机推荐
Program optimization with multi-core and multi thread
Use of mysqldump in MySQL
嵌入式编程复杂性
Canvas制作经典贪吃蛇
Research and Analysis on the current situation of China's Internet of things microcontroller market and forecast report on its development prospect (2022)
[open source tutorial] DIY tutorial of step-by-step electric adjustment [Author: I love Laurie, Laurie]
进程间通信(IPC):信号量
el-table表格循环升级版
Attention based seq2seq model
Research and Analysis on the current situation of China's fluorenone market and forecast report on its development prospect (2022)
ssh-copy-id 批量免密脚本
js Promise的运用
Cross chain revelation: has your assets really been transferred in the process of cross chain?
Huashao, founder of Kechuang · kuxuan Technology: make products with win-win thinking, connect ecology, and realize large-scale development
Importance of variables in code
UVC sterilization lamp with integrated sterilization, deodorization and odor removal
Getting started with BCC tools
【Prometheus】Prometheus联邦的一次优化记录
应用在洗衣机触摸屏中的触摸芯片
Emotron伊尔通软启动器维修MSF370/MSF450