Fix some cross-compat problem

This commit is contained in:
smarttommyau 2023-09-18 12:43:46 +08:00
parent ea4a7526c4
commit d74170536c
7 changed files with 20 additions and 19 deletions

View File

@ -38,13 +38,13 @@ void admin_menu(){
"Role control",
};
char welcome[256];
sprintf(welcome,"welcome %s(%s)\n",user->name,user->role);
bool exit = false;
do{
sprintf(welcome,"welcome %s(%s)\n",user->name,user->role);
switch (choices_selecter(Items,4,welcome))
{
case 1://action with inventory
case 1:;//action with inventory
inv_control();
break;
case 2://action with transction

View File

@ -7,7 +7,7 @@ char * show_item_admin(struct inventory db,int index);
void * show_item(void * ddb,int index);
void print_page(void * ddb, int cur, int end,struct Map* map);
struct Map* sortItems(void * ddb, int sort);
void search_item(void * (*showitem)(void *,int));
void inv_control(){
int choice = 0;
do{
@ -258,4 +258,4 @@ struct Map* sortItems(void * ddb, int sort){
map = realloc(map, sizeof(struct Map) * db.db.row_count);
map[db.db.row_count-1].key = db.db.row_count-1;
return map;
}
}

View File

@ -35,7 +35,7 @@ void normal_menu(){
},3,buf);
switch (choice)
{
case 1://List items
case 1:;//List items
struct inventory db = read_db_invt();
char * SortItems[] = {
"Name",
@ -353,7 +353,7 @@ struct cart* list_cart(struct cart* cart){
printf("<------------------------>\n");
printf("\n%d CHECKOUT\n",i);
printf("Clear Cart\n",i+1);
printf("%d Clear Cart\n",i+1);
}
do{
printf("input the corresponding value for more action\n>");

View File

@ -22,7 +22,7 @@ void role_control(){
case 1:
add_role();
break;
case 2:
case 2:;
char * SortItems[] = {
"admin",
"role",

View File

@ -16,7 +16,7 @@ void tran_control(){
"new transaction"
},2,buf);
switch(choice){
case 1:
case 1:;
char * SortItems[] = {
"Date&Time",
"product(barcode)",
@ -26,7 +26,7 @@ void tran_control(){
lister(&tran,NULL,tran.db.row_count,"Transaction",SortItems,4,print_tran,sortTrans,showTran);
break;
case 2:
add_tran(tran);
add_tran();
break;
default:
break;
@ -47,7 +47,7 @@ void print_tran(void * ddb, int cur, int end,struct Map* map){
char time[9];
sprintf(date,"%02d-%02d-%04d",db.row[index].date.day,db.row[index].date.month,db.row[index].date.year);
sprintf(time,"%02d:%02d:%02d",db.row[index].time.hour,db.row[index].time.minute,db.row[index].time.second);
printf("%-5d%-15s%-10s%-10d%-10d%-10.2lf%-10d%-10.2lf\n",i+9,date,time,db.row[index].barcode,db.row[index].id,db.row[index].price,db.row[index].quantity,total);
printf("%-5d%-15s%-10s%-10ld%-10ld%-10.2lf%-10d%-10.2lf\n",i+9,date,time,db.row[index].barcode,db.row[index].id,db.row[index].price,db.row[index].quantity,total);
}else{
double total = db.row[i].price * db.row[i].quantity;
//reconstuct date and time and print all transaction info out
@ -55,7 +55,7 @@ void print_tran(void * ddb, int cur, int end,struct Map* map){
char time[9];
sprintf(date,"%02d-%02d-%04d",db.row[i].date.day,db.row[i].date.month,db.row[i].date.year);
sprintf(time,"%02d:%02d:%02d",db.row[i].time.hour,db.row[i].time.minute,db.row[i].time.second);
printf("%-5d%-15s%-10s%-10d%-10d%-10.2lf%-10d%-10.2lf\n",i+9,date,time,db.row[i].barcode,db.row[i].id,db.row[i].price,db.row[i].quantity,total);
printf("%-5d%-15s%-10s%-10ld%-10ld%-10.2lf%-10d%-10.2lf\n",i+9,date,time,db.row[i].barcode,db.row[i].id,db.row[i].price,db.row[i].quantity,total);
}
}
}
@ -77,7 +77,7 @@ void * showTran(void * ddb,int index){
sprintf(date,"%02d-%02d-%04d",db.row[index].date.day,db.row[index].date.month,db.row[index].date.year);
sprintf(time,"%02d:%02d:%02d",db.row[index].time.hour,db.row[index].time.minute,db.row[index].time.second);
sprintf(buff+strlen(buff),"%-15s%-10s%-10s%-10s%-10s%-10s%-10s\n","Date","Time","Barcode","ID","Price","Quantity","Total");
sprintf(buff+strlen(buff),"%-15s%-10s%-10d%-10d%-10.2lf%-10d%-10.2lf\n",date,time,db.row[index].barcode,db.row[index].id,db.row[index].price,db.row[index].quantity,total);
sprintf(buff+strlen(buff),"%-15s%-10s%-10ld%-10ld%-10.2lf%-10d%-10.2lf\n",date,time,db.row[index].barcode,db.row[index].id,db.row[index].price,db.row[index].quantity,total);
choice = choices_selecter((char*[]){
"Edit transaction",
"Delete transaction",
@ -152,7 +152,7 @@ struct transaction update_tran(struct transaction db,int index){
sprintf(date,"%02d-%02d-%04d",db.row[index].date.day,db.row[index].date.month,db.row[index].date.year);
sprintf(time,"%02d:%02d:%02d",db.row[index].time.hour,db.row[index].time.minute,db.row[index].time.second);
printf("%-15s%-10s%-10s%-10s%-10s%-10s\n","Date","Time","Barcode","ID","Price","Quantity");
printf("%-15s%-10s%-10d%-10d%-10.2lf%-10d\n",date,time,db.row[index].barcode,db.row[index].id,db.row[index].price,db.row[index].quantity);
printf("%-15s%-10s%-10ld%-10ld%-10.2lf%-10d\n",date,time,db.row[index].barcode,db.row[index].id,db.row[index].price,db.row[index].quantity);
item_inputer("Date:day",INT,&db.row[index].date.day,true);
item_inputer("Date:month",INT,&db.row[index].date.month,true);
@ -246,4 +246,4 @@ struct Map* sortTrans(void * ddb,int choice){
break;
}
return map;
}
}

View File

@ -21,7 +21,7 @@ void user_control(){
case 1:
db = add_user(db);
break;
case 2:
case 2:;
char * SortItems[] = {
"Name",
"ID",

View File

@ -13,7 +13,7 @@
//for fflush_stdin
#include <stdio_ext.h>
#endif
#define PAGE_SIZE 20
#define SIZE_OF_PAGE 20
void Cls(){
#ifdef _WIN32
@ -35,11 +35,12 @@ char * welcome_message(void * ptr){ //cross compatible
if(!ptr){//if fp is NULL
return "><Welcome to the Student Union POS system><\n";
}
if(feof(ptr)){// if ptr a string or file
if(strlen(ptr)){// if ptr a string or file
sprintf(ptr,"><Welcome to the Student Union POS system><\n");//welcome message
}else{
fprintf(ptr,"><Welcome to the Student Union POS system><\n");//welcome message
}
return (char*)NULL;
}
int choices_selecter(char * Items[],int items,char * welcome_messages){
int choice = 0;
@ -74,7 +75,7 @@ char* prompt_item(char* prompt,bool empty_allowed){
printf("%s",prompt);
fflush_stdin();
scanf("%[^\n]",item);//input until /n
if(!empty_allowed&&(item,"") == 0){//check if temp is not empty
if(!empty_allowed&&strcmp(item,"") == 0){//check if temp is not empty
printf("Invalid input, try again?(y/n)\n");
char temp[100];
fflush_stdin();
@ -119,7 +120,7 @@ bool item_inputer(char * varname,INPUT_TYPE type,void * item,bool empty_allowed)
void lister(void * db,struct Map* map, int row,char * lister_name,char * SortItems[],int NoSortItems,void (*page_printer)(void*,int,int,struct Map*) , struct Map* (*sorter)(void *,int),void * (*showitem)(void *,int)){
int choice = -1;
int page = 0;
int page_size = PAGE_SIZE;
int page_size = SIZE_OF_PAGE;
int total_pages = ceil((double)row / page_size);
do{
Cls();