I'm managing in WM_COMMAND
this case where once the menu AppendMenu(hMenu,MF_POPUP (UINT_PTR)IMPORT, "import");
is pressed it will import all the data and store it in each of the variables.
I do have my structures into a header file which is called struct.h
which contains:
typedef struct userglobal{
char name[15];
int born;
float price;
float average;
}userglobal;
and here's the window procedure:
LRESULT CALLBACK WindowProcedure(HWND hWnd,UINT msg,WPARAM wp,LPARAM lp){
switch(msg){
FILE *sorgente;
int i = 0;
case WM_COMMAND:
switch(wp){
case UTENTE_OPEN:
MessageBeep(MB_OK);
break;
case RISTORANTE_OPEN:
MessageBeep(MB_ICONHAND);
break;
case UTENTE_MODIFICA:
MessageBeep(MB_ICONHAND);
break;
case 2:
MessageBox(NULL,"programma che ti permette di prenotare posti online...(da continuare)","Come Funziona?", MB_OK);
break;
case IMPORT:
if ((source = fopen("./Data/users.csv", "r")) == NULL)
printf("can't open the file.\n");
else{
while(!feof(source)){
fscanf(source,"%[^,],%d,%f,%f\n", user[i].name, &user[i].born, &user[i].price, &user[i].average);
i++;
}
}
fclose(source);
break;
case WM_CREATE:
AddMenus(hWnd);
//AddControls(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hWnd,msg,wp,lp);
}
}
I declare userglobal user[1000];
user as global scope.
When I press the import menu everything behind fscanf
in Code::Blocks will be executed while in VSCode the program will not even enter the while condition which is kind of weird. with gdb I get:
Program received signal SIGSEGV, Segmentation fault.
0x776ef391 in ungetwc ()
but I have no clue why should I get a segmentation fault.
EDIT: I've added more code into it and fixed some mistyped elements
EDIT: Fixed code:
LRESULT CALLBACK WindowProcedure(HWND hWnd,UINT msg,WPARAM wp,LPARAM lp){
switch(msg){
FILE *sorgente;
case WM_COMMAND:
switch(wp){
case UTENTE_OPEN:
MessageBeep(MB_OK);
break;
case RISTORANTE_OPEN:
MessageBeep(MB_ICONHAND);
break;
case UTENTE_MODIFICA:
MessageBeep(MB_ICONHAND);
break;
case 2:
MessageBox(NULL,"programma che ti permette di prenotare posti online...(da continuare)","Come Funziona?", MB_OK);
break;
case IMPORT:{
int i = 0;
if ((source = fopen("./Data/users.csv", "r")) == NULL)
printf("can't open the file.\n");
else{
while(!feof(source)){
fscanf(source,"%[^,],%d,%f,%f\n", user[i].name, &user[i].born, &user[i].price, &user[i].average);
i++;
}
}
fclose(source);
}
break;
case WM_CREATE:
AddMenus(hWnd);
//AddControls(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hWnd,msg,wp,lp);
}
}