Test
Test
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Define --------------------------------------------------------------------*/
#define MAX_ROW 2
#define MAX_COLUMN 15
#define MAX_ENTERPRISE 30
/* Enum ----------------------------------------------------------------------*/
typedef enum Status { Empty, Registered } Status;
if (strcmp(firstWord, "Register") == 0) {
return REGISTER;
} else if (strcmp(firstWord, "Alter") == 0) {
return ALTER;
} else if (strcmp(firstWord, "Show") == 0) {
return SHOW;
} else if (strcmp(firstWord, "Delete") == 0) {
return DELETE;
} else if (strcmp(firstWord, "Quit") == 0) {
return QUIT;
}
return INVALID;
}
getAbbreviation(name, out_abbre);
int num_abbre = strlen(out_abbre);
int booth_index;
if (booth == -1) {
}
}
if (!found) {
for (int i = booth_index; i >= 0; i--) {
if(i<15) {
if (map[0][i]==0){
booth_index = i;
found = 1;
break;
}
} else {
if(map[1][i-15]==0) {
booth_index = i;
found = 1;
break;
}
}
}
if (!found) {
*out_booth = booth_index + 100;
return;
}
}
} else {
booth_index = booth;
}
if (booth_index<15) {
if(map[0][booth_index]==0) {
map[0][booth_index]=1;
else {
*out_booth = booth_index + 100;
}
} else if(booth_index>=15){
if(map[1][booth_index-15]==0) {
map[1][booth_index-15]=1;
else {
*out_booth = booth_index + 100;
}
}
}
void showMap(int map[MAX_ROW][MAX_COLUMN], Enterprise
enterpriseArray[MAX_ENTERPRISE]) {
printf("|");
for (int j = 0; j < MAX_COLUMN; j++) {
printf("%d|", j);
}
printf("\n");
int count = 0;
for (int i = 0; i < MAX_ENTERPRISE; i++) {
if (status == Empty && enterpriseArray[i].booth_index == -1) {
count++;
count++;
}
}
if (enterpriseArray[i].booth_index==start){
printEnterpriseDetails(enterpriseArray[i]);
return;
}
}
printf("NONE\n");
return;
}
for (int i=start;i<=end;i++) {
int row=(i<15)?0:1;
int col=(i<15)?i:(i-15);
if (map[row][col]==0) {
printf("NONE\n");
}
else{
for (int j=0;j<30;j++) {
if (enterpriseArray[j].booth_index==i) {
printEnterpriseDetails(enterpriseArray[j]);
}
}
}
}
showMap(map, enterpriseArray);
} else if (strcmp(command, "Show #0") == 0) {
showTotalOfStatus(enterpriseArray,Empty );
} else if (strcmp(command, "Show #1") == 0) {
showTotalOfStatus(enterpriseArray, Registered);
} else if (cmd[0] == '[' && cmd[strlen(cmd) - 1] == ']' &&(strlen(cmd)==3||
strlen(cmd)==4 )) {
char num_str[10];
strncpy(num_str, cmd + 1, strlen(cmd) - 2);
num_str[strlen(cmd) - 2] = '\0';
}
}
void initMap(int map[MAX_ROW][MAX_COLUMN])
{
for (int i = 0; i < MAX_ROW; i++)
{
for (int j = 0; j < MAX_COLUMN; j++)
{
map[i][j] = Empty;
}
}
}