Question: the following functions must be declared/defined in separate files: database.h and database.c. int addRecord (struct record **, int, char [ ],char [ ]); void printAllRecords(struct
the following functions must be declared/defined in separate files: database.h and database.c.
int addRecord (struct record **, int, char [ ],char [ ]); void printAllRecords(struct record *); int findRecord (struct record *, int); int deleteRecord(struct record **, int);
Note: printRecord was removed.
They are stubs for now, Not sure what this means I'm new at C.
Here if this makes sense:
-
Create user_interface.c and implement your user-interface.
-
Define the following item in the main function:
struct record * start = NULL;
and pass it or its address to the database functions.
Here is my user interface:
#include
void menu() {
printf("Greetings, what do you want to do with the database? "); printf("------------------------------------------------------------------------ ");
printf(" 1. add "); printf("2. delete "); printf("3. print all "); printf("4. quit "); }
struct node* add_customer(struct node *head ,int accNo , float balance) { struct node *temp = (struct node*)malloc(sizeof(struct node)); temp->accountno = accNo; temp->balance=balance; temp->next=NULL; head->next=temp; return head; } void print(struct node *head) { struct node *temp = (struct node*)malloc(sizeof(struct node)); temp=head; printf("Details : "); while(temp!=NULL) { printf("%d ",temp->accountno); printf("%f ",temp->balance); printf(" "); temp=temp->next; }
} struct node* deleteCustomer(struct node *head, int key) { // Store head node struct node *temp = (struct node*)malloc(sizeof(struct node)); temp=head; struct node *prev = (struct node*)malloc(sizeof(struct node)); prev=NULL; // If head node itself holds // the key to be deleted if (temp != NULL && temp->accountno == key) { head = temp->next; // Changed head // free old head return head; } // Else Search for the key to be deleted, // keep track of the previous node as we // need to change 'prev->next' */ else { while (temp != NULL && temp->accountno != key) { prev = temp; temp = temp->next; } // If key was not present in linked list if (temp == NULL) return head; // Unlink the node from linked list prev->next = temp->next; return head; } }
// main method int main(int argc, char *argv[]) { struct node *head = (struct node*)malloc(sizeof(struct node)); //setting fist customer to NULL head->accountno=0; head->balance=0.0; head->next=NULL;
int flag = 1; while(flag){ menu(); printf("Enter your choice: "); //reading choice int ch ; scanf("%d", &ch); printf(" "); // use switch instead if-else if, // using switch case for menu is better. I tried using switch upon seeing Lenora's code during the meeting. switch (ch) { case 1: //reading details for bank customer printf("Enter account number: "); int accNum = 0; scanf("%d", &accNum); printf("Enter balance: "); float curbalance; scanf("%f", &curbalance); head=add_customer(head,accNum,curbalance); break; case 2: //fetching an account number, removing customer printf("Enter account number: "); int tempaccNum = 0; scanf("%d",&tempaccNum); head = deleteCustomer(head,tempaccNum); break; case 3: //printing customers print(head); break; case 4: flag=0; break; } } }
I somehow need a database to past on these I'm really confused about the database. Just try your best to help me thanks.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
