udpate and fixes

This commit is contained in:
stmctommyau 2023-11-07 01:07:45 +08:00
parent d64dbde9d4
commit baa0ed8af9
No known key found for this signature in database
GPG Key ID: 87B1991E1277F054
5 changed files with 14 additions and 5 deletions

2
main.c
View File

@ -7,7 +7,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
#include <ctype.h>Up #include <ctype.h>
#include <stddef.h> #include <stddef.h>
#endif #endif
#ifndef CUSTOM_H #ifndef CUSTOM_H

View File

@ -76,7 +76,6 @@ void search_item(void * (*showitem)(void *,int)){
break; break;
} }
char* searchstr = prompt_search(); char* searchstr = prompt_search();
printf("searching...\n");
map = searchItems(db,searchstr); map = searchItems(db,searchstr);
if(map[0].value > 0){ if(map[0].value > 0){
int temp_row = *((int*)map[0].value); int temp_row = *((int*)map[0].value);
@ -100,10 +99,11 @@ void search_item(void * (*showitem)(void *,int)){
char* prompt_search(){ char* prompt_search(){
printf("Enter search string:(largest length 100)(case insesitive)\n>"); printf("Enter search string(largest length 100)\n(case insensitive)\nmatches multiple columns\n>");
char* searchstr = malloc(sizeof(char) * 100); char* searchstr = malloc(sizeof(char) * 100);
fflush_stdin(); fflush_stdin();
scanf("%s", searchstr); scanf("%s", searchstr);
printf("searching...\n");
return searchstr; return searchstr;
} }
@ -114,7 +114,11 @@ struct Map* searchItems(struct inventory db, char* searchstr){
int k = 1; int k = 1;
for (int i = 0; i < db.db.row_count; i++){ for (int i = 0; i < db.db.row_count; i++){
map[k].key = i; map[k].key = i;
if(strcasestr(db.row[i].product,searchstr) != NULL){ if(strcasestr(db.row[i].product,searchstr) != NULL||
strcasestr(db.row[i].brand,searchstr) != NULL||
strcasestr(db.row[i].category,searchstr) != NULL||
strcasestr(lto_string(db.row[i].barcode),searchstr) != NULL
){
map[k].value = (void*)db.row[i].product; map[k].value = (void*)db.row[i].product;
k++; k++;

Binary file not shown.

Binary file not shown.

View File

@ -32,6 +32,11 @@ void fflush_stdin(){
__fpurge(stdin); __fpurge(stdin);
#endif #endif
} }
char * lto_string(long num){
char * str = malloc(sizeof(char) * 100);
sprintf(str,"%ld",num);
return str;
}
char * welcome_message(void * ptr){ //cross compatible char * welcome_message(void * ptr){ //cross compatible
@ -101,7 +106,7 @@ bool item_inputer(char * varname,INPUT_TYPE type,void * item,bool empty_allowed)
if(temp == NULL){ if(temp == NULL){
return false; return false;
} }
switch(type){ switch(type){
case INT: case INT:
*((int*)item) = atoi(temp); *((int*)item) = atoi(temp);
break; break;