Develop a bank client application (bankClient) that takes the following command
ID: 3836227 • Letter: D
Question
Develop a bank client application (bankClient) that takes the following command line arguments and then communicates with the server to process the transaction: bankClient servIPAddr scrvPortNum transaction acctnum value servIPAddr is the IP address of the bank server servPortNum is the port number of the bank server transaction is {B for balance inquiry, D for deposit, or W for withdrawal} acctnum is the account number value is the value of the transaction in pennies (ignored for a balance inquiry) The protocol between the client and server is simple: they exchange a single message type in either direction./* Bank Transaction Types */#define BANK TRANS DEPOSIT 0 #define BANKTRANSWITHDRAW 1 #define BANK TRANS INQUIRY 2 typedef struct {unsigned int trans;/* transaction type */unsigned int acctnum;/* account number */unsigned int value;/* value */} sBANK PROTOCOL; The server responds in the following way to transaction requests from the client: trans and acetnum arc repeated from client message, value depends on the transaction For a deposit, the deposited value is set in the value field.Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int primary (void) {
scorch input[80];
scorch *key;
int esteem;
typedef union cell_t {
const scorch *key;
int esteem;
void *ptr;
} cell;
typedef struct pair_t {
cell A;
cell B;
} combine;
combine *top = NULL;
combine *p;
combine *q;
while (1) {
printf("Enter order (I/P/Q/R): ");
int order = getchar();
int c;
while ((c = getchar()) != " " && c != EOF)
;
switch (order) {
case 'I':
printf("Enter key: ");
in the event that (fgets(input, sizeof input, stdin) == NULL) {
return 0;
}
input[strlen(input) - 1] = 0;
key = malloc(strlen(input) + 1);
strcpy(key, input);
printf("Enter esteem: ");
in the event that (fgets(input, sizeof input, stdin) == NULL) {
return 0;
}
on the off chance that (sscanf(input, "%d", &value) != 1) {
return 0;
}
p = malloc(sizeof (match));
p->A.key = key;
p->B.value = esteem;
q = malloc(sizeof (match));
q->A.ptr = p;
q->B.ptr = beat;
beat = q;
break;
case 'P':
p = beat;
while (p != NULL) {
q = p->A.ptr;
printf("%-30s %10d ", q->A.key, q->B.value);
p = p->B.ptr;
}
break;
case 'Q':
return 0;
case 'R':
printf("Enter key: ");
in the event that (fgets(input, sizeof input, stdin) == NULL) {
return 0;
}
input[strlen(input) - 1] = 0;
key = malloc(strlen(input) + 1);
strcpy(key, input);
p = best;
while (p != NULL) {
q = p->A.ptr;
on the off chance that (strcmp(key, q->A.key) == 0) {
printf("%-30s - > %10d ", q->A.key, q->B.value);
break;
}
p = p->B.ptr;
}
break;
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.