当前位置:网站首页>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 !
边栏推荐
- You can have a three piece set without winter. I don't allow you to have PPT, word and excel
- Arm authoritative guide and our group's project notes
- UVC sterilization lamp with integrated sterilization, deodorization and odor removal
- Distributed transaction of microservices Seata
- Huashao, founder of Kechuang · kuxuan Technology: make products with win-win thinking, connect ecology, and realize large-scale development
- 398-哈希表(242.有效的字母异位词 & 349. 两个数组的交集 & 202. 快乐数)
- 398 hash table (242. valid alphabetic words & 349. intersection of two arrays & 202. happy numbers)
- [open source tutorial] DIY tutorial of 2020 new version of brushless power regulation [Author: I love loli love loli] (brief introduction and circuit construction)
- sqli-labs-17
- 嵌入式编程复杂性
猜你喜欢

工业级的内存拷贝函数实现

Canvas制作经典贪吃蛇

Li Kou ----- result array after removing letter ectopic words

C#常用Chart组件

Metasploit入侵win7

完善业务细节

数据库是8.0的同学,在这个地方,加这一段?useSSL=false&serverTimezone=GMT%2B8&characterEncoding=utf8

Distributed transaction of microservices Seata

应用在洗衣机触摸屏中的触摸芯片

Emotron Elton soft starter maintenance msf370/msf450
随机推荐
Music genre classification based on CNN
sqli-labs-17
数字式温度传感器工作原理以及测温原理分析
Canvas makes classic Snake
Huashao, founder of Kechuang · kuxuan Technology: make products with win-win thinking, connect ecology, and realize large-scale development
Base64 format images are converted into file format images and uploaded to the server
应用在电视触摸屏中的十四通道智能触摸芯片
Research and Analysis on the current situation of LBS market in China and forecast report on its development prospect (2022)
关闭SQLite3中的journal暂存档
DP backpack summary
[grafana] optimization of grafana MIMIR in massive time series indicators
二叉排序树的基本操作
高德地图Loca 数据可视化 API 2.0的用法
Embedded development experience of RTOS group
arm权威指南及我们组项目笔记
397-链表(206.反转链表 & 24. 两两交换链表中的节点 & 19. 删除链表的倒数第 N 个结点 & 面试题 02.07. 链表相交 & 142.环形链表II)
Get string byte size
398-哈希表(242.有效的字母异位词 & 349. 两个数组的交集 & 202. 快乐数)
Research and Analysis on the current situation of China's revenue operation service market and forecast report on its development prospects (2022)
tf.compat.v1.get_default_graph