#include #include #include struct vaccine char name[20]; char code[5]; char country[10]; int dosage; int population; }; void displayvacc() { int i; int count = 0; count = readFile(); if (count < 0) puts("cannot open file"); printf(" \t\t\t   INVENTORY  \n"); printf(" NAMEVACCINE CODE|PRODUCING COUNTRY|DOSAGE REQUIRED|POPULATION COVERED  \n"); for (i=0;i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

could you pelase fix the code ?

 

#include<stdio.h>
#include<string.h>
#include <stdlib.h>
struct vaccine
char name[20];
char code[5];
char country[10];
int dosage;
int population;
};
void displayvacc()
{
int i;
int count = 0;
count = readFile();
if (count < 0)
puts("cannot open file");
printf(" \t\t\t   INVENTORY  \n");
printf(" NAMEVACCINE CODE|PRODUCING COUNTRY|DOSAGE REQUIRED|POPULATION COVERED  \n");
for (i=0;i<count;i++)
{
printf("%s   %-10s   %-8s   %-6d   %-4d  \n", i+1, vacc[i].name,vacc[i].code,vacc[i].country,vacc[i].dosage,vacc[i].population);
}
}
void addvacc()
{
printf("Enter New Vaccine\n");
readFile();
if (count>0) 
{
CODEChecker(0,count);
}
else
{
printf("\nVaccine Name: ");
fflush(stdin);
gets(vacc[count].name);
}
printf("Vaccine Code: ");
gets(vacc[count].code);
printf("Producing Country: ");
gets(vacc[count].country);
printf("Dosage Required: ");scanf("%d",&vacc[count].dosage);
printf("Percentage Population Covered : ");scanf("%d",&vacc[count].dosage);
writefile();
}
void deletevacc()
{
count=readFile();
char code[5];
int i,j;
int z=false;
printf("Enter Code of Vaccine to delete: ");
fflush(stdin);
gets(code);
for(i=0;i<count;i++)
{
z=true;
if(strcmp(vacc[i].code,code)==0)
{
for( j=i; j<(count-1); j++)
{
vacc[j]=vacc[j+1];
}
count--;
}
}
if(z==false)
{
}
writefile();
}
void editvacc()
{
char code[5];
int test;
int i;
int choice;
printf("Edit Vaccine!");
printf("\nEnter the code of vaccine to edit: "); 
fflush(stdin);
gets(code);
test=checkCODE(code);
if (test == 0)
{
printf("The code %s is not found.", code); 
else
{
readFile();
{
for(i=0;i<count;i++)
{
if(strcmp(id,vacc[i].code)!=0) 
writefile();
else
{
printf("\n 1. Update Name of Vaccine?");
printf("\n 2. Update Vaccine Code?");
printf("\n 3. Update Producing Country?");
printf("\n 4. Update Dosage Required?");
printf("\n 5. Update Population Covered?");
printf("\n Enter choice:");
fflush(stdin);
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("Enter new Name: ");
fflush(stdin);
gets(vacc[i].name);
break;
case 2:
printf("Enter new Code: ");
fflush(stdin);
gets(vacc[i].code);
break;
case 3:
printf("Enter new Country: ");
fflush(stdin);
gets(vacc[i].country);
break;
case 4:
printf("Enter new Dosage: ");
scanf("%d",&vacc[i].dosage);
break;
case 5:
printf("Enter new Population: ");
scanf("%d",&vacc[i].population);
default:
printf("Wrong Choice");
break;
}
writefile();
}
}
}
fclose(f); 
f = fopen("Vaccine inventory.txt", "r");
readFile();
{
writefile();
}
fclose(f);
Printf("Inventory Updated");
}
}
int checkCODE(char code[])

int i;
count=readFile();
readFile();
for(i=0;i<count;i++)
{        
if(strcmp(code,vacc[i].code)!=0)
{   
fclose(f);
}
return 1;   
}   
fclose(f);
return 0; 
}
int main ()
{
int choice;
count = readFile();
if(count < 0)
printf("Cannot locate file\n");
do
{
printf("\n");
printf("\t\t\t    VACCINE INVENTORY MANAGEMENT SYSTEM \n");
printf("\t\t\t  ........................................");
printf("\nPress:");
printf("\n 1.) Display all vacinnes.");
printf("\n 2.) Add new Vacinne.");
printf("\n 3.) Edit Vacinne.");
printf("\n 4.) Delete a Vaccine");
printf("\n 5.) Exit the Inventory.");
printf("\n Enter Choice__: ");
scanf("%d", &choice);
switch(choice)
{
case 1:
displayvacc();
break;
case 2:
addvacc();
break;
case 3:
editvacc();                       
break;
case 4:
deletevacc();                       
break;
case 5:
exit(1);
break;
default :
printf("Wrong choice, please try another option!!");
}

while(choice!=5);
printf("Thank you");
}
struct vaccine vacc[30];
int count = 0;
FILE *f;
int writefile()
{
int i;
f = fopen("Vaccine inventory.txt", "w");
if (f == NULL)
return -1;
fprintf(f, "%d\n", count);
for (i = 0; i < count; ++i)
{
fputs(vacc[i].name, f);
fprintf(f, "\n");
fputs(vacc[i].code, f);
fprintf(f, "\n");
fputs(vacc[i].country, f);
fprintf(f, "\n");
fprintf(f, "%d\n", vacc[i].dosage);
fprintf(f, "%d\n", vacc[i].population);
}
fclose(f);
return 0;
}
int readFile()
{
int n = 0;
int i;
f = fopen("Vaccine inventory.txt", "r");
if (f == NULL)
return -1;
fscanf(f, "%d\n", &n);
for (i = 0; i < n; ++i)
{
fgets(vacc[i].name, 30, f);
vacc[i].name[strlen(vacc[i].name)-1] = 0;
fgets(vacc[i].code, 5, f);
vacc[i].code[strlen(vacc[i].code)-1] = 0;
fgets(vacc[i].country, 10, f);
vacc[i].country[strlen(vacc[i].country)-1] = 0;
fscanf(f, "%d", &vacc[i].dosage);
fscanf(f, "%d", &vacc[i].population);
}
fclose(f);
return n;
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education