06-06-21, 09:54 PM
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct meds{
char name[30];
char comp_name[100];
char date[30];
char exp[30];
int Id, quan, price;
};
struct meds *acct;
void instructions(void){
printf("Enter the number of the command.\n"
"Enter 1 to add a new medicine.\n"
"Enter 2 to delete a medicine.\n"
"Enter 3 to update a medicine.\n"
"Enter 4 to print all Medicines in stock.\n"
"Enter 5 to buy a medicine.\n"
"Enter 0 to Exit the program.\n");
}
int main()
{
instructions();
char file(){
FILE *fPtr;
char medname[50];
//int choice, medid;
fPtr = fopen("meds.txt", "w");}
//instructions();
int choice;
int medid;
scanf("%d", &choice);
struct meds record;
if (choice ==1){
nextmedicine(&record);}
/*else if (choice==2){
deletemedicine();
}*/
//struct meds record;
int flag = 0;
//nextmedicine(&record);
/*if ((strcmp(record.name, "End") == 0) &&
(strcmp(record.name, "Customer") == 0))
{
flag = 1;
}*/
/*if (flag != 1){
printmedicine(record);
}*/
return printmedicine(record);
}
int nextmedicine(struct meds *acct) {
//printf("Enter names: (firstName lastName): " );
printf("Enter Medicine Id:\n");
scanf("%d", &acct->Id);
printf("Enter medicine name:\n");
scanf("%s", acct->name);
//printf("Enter account number: ");
printf("Enter company name:\n");
scanf("%s", acct->comp_name);
//printf("Enter balance : ");
/*printf("Production company:\n");
scanf("%s", acct->comp_name);*/
printf("Enter Quantity:\n");
scanf("%d", &acct->quan);
printf("Enter Manufactured date:\n");
scanf("%s",acct->date);
printf("Enter Expiry date:\n");
scanf("%s",acct->exp);
printf("Enter Price:\n");
scanf("%d", &acct->price);
printf("Medicine with id %d Added Successfully\n", acct->Id);
}
int printmedicine(struct meds acct) {
printf("%13s%13s%13d%d%13s%13s%13d\n", acct.name, acct.comp_name ,acct.Id, acct.quan , acct.date , acct.exp, acct.price);
FILE *fptr;
fptr = fopen("meds.txt", "a");
fprintf(fptr, "%s%13s%13d%13d%13s%13s%13d\n", acct.name, acct.comp_name ,acct.Id, acct.quan , acct.date , acct.exp, acct.price);
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
مرحبا
عندي هذا الكود في الأعلى واريد عمل ميزة التعديل و المسح (الحذف) ممكن حدا يساعدني وشكراُ ؟؟
#include<stdlib.h>
#include<string.h>
typedef struct meds{
char name[30];
char comp_name[100];
char date[30];
char exp[30];
int Id, quan, price;
};
struct meds *acct;
void instructions(void){
printf("Enter the number of the command.\n"
"Enter 1 to add a new medicine.\n"
"Enter 2 to delete a medicine.\n"
"Enter 3 to update a medicine.\n"
"Enter 4 to print all Medicines in stock.\n"
"Enter 5 to buy a medicine.\n"
"Enter 0 to Exit the program.\n");
}
int main()
{
instructions();
char file(){
FILE *fPtr;
char medname[50];
//int choice, medid;
fPtr = fopen("meds.txt", "w");}
//instructions();
int choice;
int medid;
scanf("%d", &choice);
struct meds record;
if (choice ==1){
nextmedicine(&record);}
/*else if (choice==2){
deletemedicine();
}*/
//struct meds record;
int flag = 0;
//nextmedicine(&record);
/*if ((strcmp(record.name, "End") == 0) &&
(strcmp(record.name, "Customer") == 0))
{
flag = 1;
}*/
/*if (flag != 1){
printmedicine(record);
}*/
return printmedicine(record);
}
int nextmedicine(struct meds *acct) {
//printf("Enter names: (firstName lastName): " );
printf("Enter Medicine Id:\n");
scanf("%d", &acct->Id);
printf("Enter medicine name:\n");
scanf("%s", acct->name);
//printf("Enter account number: ");
printf("Enter company name:\n");
scanf("%s", acct->comp_name);
//printf("Enter balance : ");
/*printf("Production company:\n");
scanf("%s", acct->comp_name);*/
printf("Enter Quantity:\n");
scanf("%d", &acct->quan);
printf("Enter Manufactured date:\n");
scanf("%s",acct->date);
printf("Enter Expiry date:\n");
scanf("%s",acct->exp);
printf("Enter Price:\n");
scanf("%d", &acct->price);
printf("Medicine with id %d Added Successfully\n", acct->Id);
}
int printmedicine(struct meds acct) {
printf("%13s%13s%13d%d%13s%13s%13d\n", acct.name, acct.comp_name ,acct.Id, acct.quan , acct.date , acct.exp, acct.price);
FILE *fptr;
fptr = fopen("meds.txt", "a");
fprintf(fptr, "%s%13s%13d%13d%13s%13s%13d\n", acct.name, acct.comp_name ,acct.Id, acct.quan , acct.date , acct.exp, acct.price);
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
مرحبا
عندي هذا الكود في الأعلى واريد عمل ميزة التعديل و المسح (الحذف) ممكن حدا يساعدني وشكراُ ؟؟