Commit 2c9e945c by karade

Update broneering.c

parent ecae42cc
Showing with 121 additions and 3 deletions
......@@ -9,19 +9,25 @@
int main(void)
{
int seatmap[ROWS][COLS]= {0};
srand(time(NULL));
int i = 0;
users data[SEAT_MAX];
int cont = 0;
puts("Choose destination\n");
MYSQL* con = connectToMySQLServer();
puts("Choose destination\n");
int flightId = ShowDestinations(con);
data[i].flight_id = flightId;
FillSeatmap(seatmap, ROWS, COLS, con, flightId);
PrintSeats(seatmap, ROWS, COLS);
while(cont == 0)
{
printf("\nChoose seat"); //kontrolli ja plaani kuvamise funktsioon lisada
printf("\nChoose seat"); //kontroll lisamata
char seat[SEAT_MAX];
scanf("%s", seat);
strcpy(data[i].seat, seat);
......@@ -58,7 +64,10 @@ int main(void)
data[i].checkedIn = false;
printf("\nWhat luggage do you want to bring with you:");
printf("\nWhat luggage do you want to bring with you");
puts("\n0-Small bag + Carry-On(default included in fare),"
"1-Check-In 20kg suitcase, 2-Oversized(bikes, 20+kg)");
puts("Enter value:");
int luggage;
scanf("%d", &luggage);
data[i].luggageClass = luggage;
......@@ -71,6 +80,115 @@ int main(void)
}
}
void FillSeatmap(int seats[ROWS][COLS], int rows, int cols, MYSQL *con, int flightId)
{
char query[512];
sprintf(query, "SELECT seat FROM users WHERE flight_id = %d;", flightId);
if (mysql_query(con, query)) { //päring serverile
printf("Error getting seat data: %s\n", mysql_error(con));
exit(EXIT_FAILURE);
}
MYSQL_RES *result = mysql_store_result(con);
int num_fields = mysql_num_fields(result);
char temp[4];
char tempRow[3];
int tempRowInt;
char colNum;
int col;
MYSQL_ROW row;
while ((row = mysql_fetch_row(result)))
{
for(int i = 0; i < num_fields; i++)
{
//printf("%s ", row[i] ? row[i] : "NULL");
strcpy(temp,row[i]);
strncpy(tempRow, temp, 2);
tempRow[2] = '\n';
tempRowInt = atoi(tempRow);
colNum = temp[2];
if (colNum == 'A')
{
col = 0;
}
else if (colNum == 'B')
{
col = 1;
}
else if (colNum == 'C')
{
col = 2;
}
else if (colNum == 'D')
{
col = 3;
}
seats[tempRowInt][col] = 1;
}
//printf("\n");
}
}
void PrintSeats(int data[ROWS][COLS], int rows, int cols)
{
int i, j;
char colId;
printf("\nSeats available :\n");
for(i = 0; i < rows; i++)
{
for(j = 0; j < cols; j++)
{
if (j == 0)
{
colId = 'A';
}
else if (j == 1)
{
colId= 'B';
}
else if (j == 2)
{
colId = 'C';
}
else if (j == 3)
{
colId = 'D';
}
if(data[i][j] == 1)
{
printf("\033[0;31m");
printf(" X ");
printf("\033[0m");
}
else if(data[i][j] == 0)
{
printf("\033[0;32m");
if(i < 10)
printf("0%d%c", i, colId);
else
printf("%d%c", i, colId);
printf("\033[0m");
}
if(j == 1)
printf("\t");
else
printf(" ");
}
printf("\n");
}
}
void insertPersonIntoTable(MYSQL* con, users data)
{
char query[1024]; //salvestan mysql päringu stringi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment