During the outbreak , Because the school informed us that the curriculum design was not limited by the physical environment , therefore C The language course is set up as promised ... Just finished C Language curriculum design is very painful indeed ( Not yet c Didn't learn the language well ), I think there will be a lot of people like me looking for code on the Internet , Or the knowledge points of the linked list file , But in the end, I have to find the code that meets the teacher's requirements on the Internet , Don't talk much , Direct code .
#include "singlelist.h" void medicine_menu()// Main menu { printf("\t----- Hello! You
have entered the management system of pharmacy -----\n\n"); printf(
"\t\t\t\t\t\t\t\t\tMENU\n\n"); printf("\t\t\t Enter 1 to add the message of
medicine.\n");// add to printf("\t\t\t Enter 2 to check the message of medicine.\n");
// see printf("\t\t\t Enter 3 to revise the message of medicine.\n");// modify printf(
"\t\t\t Enter 4 to search medicine with its number.\n");// Find by number printf("\t\t\t
Enter 5 to sort medicine by price.\n");// Sort by price printf("\t\t\t Enter 6 to delete
the message of medicine.\n");// Delete information printf("\t\t\t Enter 7 to exit this
system.\n");// sign out printf(
printf("\t\t\t Please enter the number (1 ~ 7) :"); } drug *list; void input()
// User input { int choice = 0; medicine date; drug *pMove = NULL; scanf("%d",&choice);
switch(choice) { case 1:// Add information printf("\t\t\t\t\t----------[ADD
MESSAGES]----------\n"); printf("\t\tPlease enter the
number,name,MFD,EXP,price,inventory,brand and function\n"); printf("\t\t");
fflush(stdin); scanf("%s %s %s %s %lf %s %s %s", date.number,date.name,date.MFD,
date.EXP,&date.price,date.inventory,date.brand,date.function); insert(list, date
); break; case 2:// View all information printf("\t\t\t\t\t----------[Check
Information]----------\n"); print(list); break; case 3:// Modify information printf(
"\t\t\t\t\t----------[Revise Information]----------\n"); printf("\t\tPlease
enter the number needed to be revised:"); scanf("%s",date.number); if(search(
list, date.number) == NULL) { printf("Erro\n"); } else { drug *node = search(
list, date.number); printf("\t\tPlease enter the number,name,MFD,EXP,price,
inventory,brand and function\n\t\t"); scanf("%s %s %s %s %lf %s %s %s",node->
->date.inventory,node->date.brand,node->date.function); } break; case 4:// Find drug information
printf("\t\t\t\t\t----------[Search Information]----------\n"); printf(
"\tPlease enter the number needed to be searched:"); scanf("%s" , date.number);
pMove= search(list, date.number); if(pMove == NULL) { printf("Erro\n"); system(
"pause"); } else { printf("\t\t\tThe number of the medicine--------%s\n",pMove->
date.number); printf("\t\t\tThe name of the medicine----------%s\n",pMove->date.
name); printf("\t\t\tThe MFD of the medicine-----------%s\n",pMove->date.MFD);
printf("\t\t\tThe EXP of the medicine-----------%s\n",pMove->date.EXP); printf(
"\t\t\tThe price of the medicine---------%.2f\n",pMove->date.price); printf(
"\t\t\tThe inventory of the medicine-----%s\n",pMove->date.inventory); printf(
"\t\t\tThe brand of the medicine---------%s\n",pMove->date.brand); printf(
"\t\t\tThe function of the medicine------%s\n",pMove->date.function); } break;
case 5:// sort printf("The result of the compositor from low to high is :\n"); sort
(list); Display(list); break; case 6:// Delete information printf("\t\t\t\t\t----------[Delete
Information]----------\n"); printf("Please enter the number needed to be
deleted:"); scanf("%s",date.number); delet(list, date.number); break; case 7:
printf("exit"); system("pause"); exit(0); break; default: printf(
"\n\t\t\t\tErro\n"); system("pause"); break; } writeInfoToFile(list,"1.txt"); }
int main(void) { list = creatlist(); printf(
printf("\t-------------------- Welcome to management
system--------------------\n"); printf("\t------------------ Press any key to
enter the menu-------------------\n"); printf(
; getchar(); readInfoFromFile(list,"1.txt"); while (1) { medicine_menu(); input(
); system("pause"); system("cls"); } return 0; }
These are main.c Content in file , Let's see singlelist.h Contents of this header file
#ifndef singlelist_h #include <stdio.h> #include <string.h> #include <math.h> #
include <stdlib.h> typedef struct medicine{ char number[10];// Drug No char name[50]
;// Drug name char MFD[50];// date of manufacture char EXP[50];// quality guarantee period double price;// Price char inventory[
50];// Inventory quantity char brand[50];// brand char function[100];// Drug function }medicine; typedef
struct drug{ medicine date; struct drug *next; }drug; drug * creatlist()// Create a linked list {
drug*head = (drug*)malloc(sizeof(drug)); head->next = NULL; return head; } drug
* creatNode(medicine date)// Create node { drug *newnode = (drug*)malloc(sizeof(drug));
newnode->date = date; newnode->next = NULL; return newnode; } void insert(drug *
head, medicine date)// Input information ( Head insertion ) { drug *newNode = creatNode(date); newNode->next
= head->next; head->next = newNode; } void delet(drug *head , char *number)
// Delete information by number { drug *posNode = head->next; drug *posFrontnode = head; if(posNode
== NULL)// If there is no data in the linked list { printf("Erro\n"); return; } else { while (strcmp(posNode->
date.number,number))// Compare the original data with the input data { posFrontnode = posNode; posNode =
posFrontnode->next; if( posNode == NULL) { printf("Erro\n"); return; } }
posFrontnode->next = posNode->next; free(posNode); } } drug *search(drug *head,
char *number)// Find information by number { drug *pMove = head->next; if(pMove == NULL) { return
NULL; } while(strcmp(pMove->date.number , number)) { pMove = pMove->next; }
return pMove; } void sort(drug *L) { drug *p,*pre,*q; p = L->next->next;
//p point L Of 2 Data nodes L->next->next = NULL; while (p != NULL) { q = p->next;
//q preservation *p Pointer of node successor node pre = L; // Compare from header while (pre->next != NULL && (pre->next->
date.price < pre->date.price)) { pre = pre->next; // Find insert in ordered table *p Forward node of *pre } p->
next= pre->next; pre->next = p; p = q; // Scan the remaining nodes of the original single chain table } } void Display(drug *L) {
drug*p = L->next; //p Point to the first node ( Not necessarily the head node ) while( p!= NULL) { printf("\t\t%s
%.2lf\n",p->date.name,p->date.price); p = p->next; } printf("\n"); } void
readInfoFromFile(drug *headnode, char*fileName) { //1. Open file FILE*fp; medicine
date; fp=fopen(fileName,"r"); if(fp == NULL) { fp=fopen(fileName,"w+"); }
//2. read file while(fscanf(fp,"%s\t%s\t%s\t%s\t%lf\t%s\t%s\t%s\t\n",date.number,date.
name,date.MFD,date.EXP,&date.price,date.inventory,date.brand,date.function) !=
EOF) { insert(headnode,date); } //3. Close file fclose(fp); } // File write operation void
writeInfoToFile(drug *headnode, char*fileName) { FILE*fp; fp = fopen(fileName,
"w"); drug *pMove = headnode->next; while(pMove) { fprintf(fp,
brand,pMove->date.function); pMove=pMove->next; } fclose(fp); } void print(drug
* head)// Print all information { drug *p = head->next; while (p) { printf("\t\t\tThe number of
the medicine--------%s\n",p->date.number); printf("\t\t\tThe name of the
medicine----------%s\n",p->date.name); printf("\t\t\tThe MFD of the
medicine-----------%s\n",p->date.MFD); printf("\t\t\tThe EXP of the
medicine-----------%s\n",p->date.EXP); printf("\t\t\tThe price of the
medicine---------%.2f\n",p->date.price); printf("\t\t\tThe inventory of the
medicine-----%s\n",p->date.inventory); printf("\t\t\tThe brand of the
medicine---------%s\n",p->date.brand); printf("\t\t\tThe function of the
medicine------%s\n",p->date.function); printf("\n"); p = p->next; } printf("\n")
; } #endif In fact, these management systems basically mean the same thing , It only requires proficient operation of linked list and file , If it's not the pharmacy management system, it's other systems as : Book management system ,
Student management system , Star management system, etc , On this basis, you can modify the structure members , Or modify the function function itself .
At last, I wish you all the courses passed smoothly !

©2019-2020 Toolsou All rights reserved,
html Writing about cherry trees , Writing about cherry trees It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) Browser kernel ( understand )HashMap Explain in detail java Four functional interfaces ( a key , simple )os Simple use of module Some East 14 Pay change 16 salary , Sincerity or routine ?