Professional Documents
Culture Documents
C Miniproject
C Miniproject
Samyuktha Ganeshkumar(195001095)
Varsha.S(195001121)
Sanjana.A(195001097)
June 14 2020
–To create an alert system for the pharmacist when medicines go out
of stock or expire
LIBRARIES
3 header libraries were created with functions needed for the customer
and the pharmacist user path and included in the main.c program.
A printout of the entire sample input output has been attached at the
last.
GENERAL.H
//
// Created by SAMMU on 5/6/20.
//
#ifndef CMINIPROJECT_GENERAL_H
#define CMINIPROJECT_GENERAL_H
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{
int day,month,year;
}date;
typedef struct{
int id;
char name[50];
date mfg,expiry;
int price;
int stock;
}drug;
date sys_date(void);
int rand_order(void);
#endif // CMINIPROJECT_GENERAL_H
GENERAL.C
//
// Created by SAMMU on 5/6/20.
//
#include "general.h"
date sys_date(void){
date sys_date;
time_t T= time(NULL);
struct tm tm;
tm = *localtime(&T);
sys_date.day=tm.tm_mday;
sys_date.month=tm.tm_mon+1;
sys_date.year=tm.tm_year+1900;
return sys_date;
//generate random id
int rand_order(void){
srand(time(0));
return num;
PHARMACIST.H
//
// Created by SAMMU on 4/6/20.
//
#ifndef CMINIPROJECT_PHARMACIST_H
#define CMINIPROJECT_PHARMACIST_H
#include "general.h"
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdio.h>
typedef struct{
char mobile[11];
char password[11];
}pharmacist;
int rand_id(void);
#endif // CMINIPROJECT_PHARMACIST_H
PHARMACIST.C
//
// Created by SAMMU on 4/6/20.
//
#include "pharmacist.h"
int rand_id(void) {
int num = 0;
srand(time(0));
return num;
FILE * fp;
fp = fopen(fname, "a");
drug new_drug;
new_drug.id = rand_id();
printf("\nDrug: ");
scanf("%s", new_drug.name);
printf("\nPrice: ");
scanf("%d", & new_drug.price);
getchar();
fclose(fp);
return;
//delete drug
drug new_drug;
int found = 0;
fp = fopen(fname, "r");
pharmacist person;
if (feof(fp)) {
printf("\nInventory empty!!!");
return;
}
if (!fp_tmp) {
fclose(fp);
fclose(fp_tmp);
int drug_id;
printf("\nDrug ID to be deleted: ");
scanf("%d", & drug_id);
if (drug_id == new_drug.id) {
printf("\nDrug found and deleted from inventory.");
found = 1;
} else {
fprintf(fp_tmp, " %d %s %d %d %d %d %d %d %d %d", new_drug.id,
new_drug.name, new_drug.mfg.day, new_drug.mfg.month, new_drug.mfg.year,
new_drug.expiry.day, new_drug.expiry.month, new_drug.expiry.year, new_drug.price,
new_drug.stock);
}
}
if (!found) {
printf("\n%d not found in inventory.", drug_id);
}
remove(fname);
rename("tmp.txt", fname);
return;
}
drug new_drug;
int choice;
int found = 0;
pharmacist person;
fp = fopen(fname, "r");
if (feof(fp)) {
fclose(fp);
printf("\nInventory empty!!!");
return;
}
if (!fp_tmp) {
printf("\nUnable to open temp file.");
return;
}
found = 1;
switch (choice) {
case 1:
scanf("%s", new_drug.name);
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
} else {
fclose(fp);
fclose(fp_tmp);
remove(fname);
rename("tmp.txt", fname);
return;
}
FILE * fp;
date today;
drug new_drug;
today = sys_date();
sys_day = today.day;
sys_mon = today.month;
sys_year = today.year;
pharmacist person;
fp = fopen(fname, "r");
if (feof(fp)) {
fclose(fp);
return;
}
}
if (new_drug.stock == 0 && !feof(fp)) {
fclose(fp);
return;
void account_pharmacist(void) {
pharmacist person;
scanf("%s", person.mobile);
char fname[15];
strcpy(fname, person.mobile);
strcat(fname, ".txt");
FILE * fp1;
fclose(fp1);
fp = fopen(fname, "r");
if (fp) {
fclose(fp);
return;
}
fclose(fp);
scanf("%s", person.password);
fp = fopen(fname, "w");
fclose(fp);
printf("\nCongratulations your account has been created!!! Access it with your mobile
number as the username and the password you have entered.");
return;
//login
pharmacist person;
scanf("%s", person.mobile);
strcpy(fname, person.mobile);
FILE * fp;
fp = fopen(fname, "r");
if (fp == NULL) {
fclose(fp);
return 2;
}
fclose(fp);
char psw[11];
scanf("%s", psw);
getchar();
if (strcmp(person.password, psw) == 0) {
return 1;
} else {
return 0;
}
}
drug new_drug;
pharmacist person;
fp = fopen(fname, "r");
if (feof(fp)) {
fclose(fp);
return;
}
if (feof(fp)) {
break;
}
}
fclose(fp);
return;
}
CUSTOMER.H
//
// Created by SAMMU on 5/6/20.
//
#ifndef CMINIPROJECT_CUSTOMER_H
#define CMINIPROJECT_CUSTOMER_H
#include "general.h"
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdio.h>
#include "pharmacist.h"
typedef struct{
char name[50];
char email[50];
char mobile[11];
char password[11];
}customer;
#endif // CMINIPROJECT_CUSTOMER_H
CUSTOMER.C
//
// Created by SAMMU on 5/6/20.
//
#include "customer.h"
void add_cart(drug * ptr, int no_sellers, char ** sellers, int id, int quantity, int cart_count) {
int found = 0;
drug new_drug;
pharmacist person;
if (feof(fp)) {
fclose(fp);
printf("\nInventory empty!!!");
return;
}
found = 1;
continue;
}
new_drug.stock -= quantity;
new_drug.stock = quantity;
ptr[cart_count] = new_drug;
} else {
fclose(fp);
if (!found) {
printf("\n%d not found in inventory.", id);
}
return;
}
void delete_cart(drug * ptr, int no_sellers, char ** sellers, int id, int quantity,
drug * ptr1, int cart_count, int new_cart_count) {
int found = 0;
drug new_drug;
pharmacist person;
if (feof(fp)) {
fclose(fp);
printf("\nInventory empty!!!");
return;
}
found = 1;
new_drug.stock += quantity;
} else {
}
}
fclose(fp);
fclose(fp_tmp);
if (ptr[j].id != id) {
ptr1[i] = ptr[j];
}
}
return;
}
int i = 0, order;
FILE * fp;
char address[50];
scanf("%s", address);
getchar();
fp = fopen(fname_customer, "a");
order = rand_order();
fprintf(fp, " %d %s -%d units", (ptr + i) - > id, (ptr + i) - > name, (ptr + i) - > stock);
printf("%d %s - %d units", (ptr + i) - > id, (ptr + i) - > name, (ptr + i) - > stock);
i++;
}
fclose(fp);
return;
}
void account_customer(void) {
customer person;
char fname[15];
strcpy(fname, person.mobile);
strcat(fname, ".txt");
FILE * fp;
fp = fopen(fname, "r");
if (fp) {
fclose(fp);
return;
}
fclose(fp);
scanf("%s", person.password);
fp = fopen(fname, "w");
fclose(fp);
printf("\nCongratulations your account has been created!!! Access it with your mobile
number as the username and the password you have entered.");
return;
//login
customer person;
scanf("%s", person.mobile);
strcpy(fname, person.mobile);
strcat(fname, ".txt");
FILE * fp;
fp = fopen(fname, "r");
if (fp == NULL) {
fclose(fp);
printf("\nAccount does not exist!");
return 2;
}
char psw[11];
if (strcmp(person.password, psw) == 0) {
fclose(fp);
return 1;
} else {
printf("\nYou have typed in the wrong password!");
fclose(fp);
return 0;
}
int no_sellers(void) {
FILE * fp;
int i = 0;
char seller[15];
fp = fopen("sellers.txt", "r");
i++;
};
fclose(fp);
return i;
}
//print cart
return;
}
MAIN.C
#include "general.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "pharmacist.h"
#include "customer.h"
int main() {
char c;
int c1;
char login[15];
int success;
int logout = 0;
printf(" WELCOME!"
"\n ...SVS ONLINE PHARMACY..."
"\n All your medicines in one place!!!");
c = getchar();
getchar();
switch (c) {
case 'p':
c1 = getchar();
getchar();
if (c1 == 'n') {
account_pharmacist();
}
do {
success = login_pharmacist(login);
if (success == 2) {
account_pharmacist();
}
print_stock(login);
alert(login);
while (logout == 0) {
switch (c1) {
case 1:
add_drug(login);
break;
case 2:
case 3:
update_drug(login);
break;
case 4:
print_stock(login);
break;
case 5:
logout = 1;
break;
default:
break;
case 'c':
{
c1 = getchar();
getchar();
if (c1 == 'n') {
account_customer();
}
do {
success = login_customer(login);
if (success == 2) {
int seller_count;
FILE * fp1;
seller_count = no_sellers();
printf("\n\nShop medicines....");
fclose(fp1);
int cart_count;
int new_cart_count,
drug_id,
quantity,
remove;
printf("\nYour cart is empty!!!....\nHow many medicines would you like to add from
the list above to the cart? ");
printf("\nID,Quantity: ");
scanf("%d %d", & drug_id, & quantity);
add_cart(cart, seller_count, sellers, drug_id, quantity, j);
}
char c2;
while (logout == 0) {
switch (c1) {
case 1:
{
printf("\nHow many medicines would you like to add from the list to the cart? ");
cart_count += new_cart_count;
printf("\nEnter medicine IDs and quantities you would like to add to cart.... ");
case 2:
{
c2 = getchar();
getchar();
if (c2 == '#') {
break;
}
printf(
"\nHow many medicines would you like to remove from the cart? ");
printf("\nEnter medicine IDs and quantities you would like to remove from cart....
");
break;
}
free(cart);
c2 = getchar();
getchar();
if (c2 == '1') {
printf("\nHow many medicines would you like to add from the list to the cart? ");
printf("\nEnter the medicine's ID you would like to purchase and their respective
quantities....");
printf("\nID,Quantity: ");
scanf("%d %d", & drug_id, & quantity);
add_cart(cart, seller_count, sellers, drug_id, quantity, j);
}
} else {
logout = 1;
}
break;
}
case 4:
buy(cart, login);
break;
case 5:
break;
case 6:
{
fclose(fp1);
break;
}
case 7:
logout = 1;
break;
}
}
free(cart);
free(sellers);
break;
}
}
printf(" THANK YOU for visiting our website!!!....STAY SAFE AND STAY
HOME!");
exit(0);
}