menu and sub menu
-
I want to create a submenu which uses the case statements. So my problem is the program crushes and i can't get the logic how i can arrange the case statements. Please help me, i am already under pressure because of time. I want the program run such that if i enter option 1 it create a process and then produce which i can now suspend the process from there or shut it down in the submenu Here is my code
#include #include #include #include #include #include #include typedef struct _iobuf FILE; #include #include #include int menu(void) { char iobuf[80]; int choice; int i,len,valid; //HANDLE hProcess; printf ("\n"); printf ("*****************************************\n"); printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n"); printf ("========================================="); printf ("\n=\t 1: Create a process \t\t="); printf ("\n=\t 2: Quit the system\t\t="); printf ("\n=========================================\n"); valid=0; printf("\nEnter choice (1-3): "); while( valid == 0) { fgets(iobuf,sizeof(iobuf),stdin); // remove '\n' len = strlen(iobuf)-1; iobuf[len] = 0; // validate data valid = 1; // assume valid input for(i = 0; i < len; i++) { if( !isdigit(iobuf[i])) { printf("\nPlese enter numeric digits only (1-5)\n"); valid = 0; } } } choice = atoi(iobuf); return choice; } int submenu(void) { char iobuf[80]; int choice2; int i,len,valid; //HANDLE hProcess; PROCESS_INFORMATION pi; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ HANDLE hProcess; DWORD lpAddr = 0; TCHAR lpApplicationName[_MAX_PATH]=""; int result; char ans [4]=""; //int choice; printf ("\n*****************************************\n"); printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n"); printf ("========================================="); printf ("\n=\t 1: Suspend the process\t\t="); printf ("\n=\t 2: Resume process \t="); printf ("\n=\t 3: Shutdown the process \t="); printf ("\n=\t 4: Exit the system \t="); printf ("\n=========================================\n"); printf ("\n"); valid=0; printf("\nEnter choice (1-4): "); while( valid == 0) { fgets(iobuf,sizeof(iobuf),stdin); // remove '\n' len = strlen(iobuf)-1; iobuf[len] = 0;
-
I want to create a submenu which uses the case statements. So my problem is the program crushes and i can't get the logic how i can arrange the case statements. Please help me, i am already under pressure because of time. I want the program run such that if i enter option 1 it create a process and then produce which i can now suspend the process from there or shut it down in the submenu Here is my code
#include #include #include #include #include #include #include typedef struct _iobuf FILE; #include #include #include int menu(void) { char iobuf[80]; int choice; int i,len,valid; //HANDLE hProcess; printf ("\n"); printf ("*****************************************\n"); printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n"); printf ("========================================="); printf ("\n=\t 1: Create a process \t\t="); printf ("\n=\t 2: Quit the system\t\t="); printf ("\n=========================================\n"); valid=0; printf("\nEnter choice (1-3): "); while( valid == 0) { fgets(iobuf,sizeof(iobuf),stdin); // remove '\n' len = strlen(iobuf)-1; iobuf[len] = 0; // validate data valid = 1; // assume valid input for(i = 0; i < len; i++) { if( !isdigit(iobuf[i])) { printf("\nPlese enter numeric digits only (1-5)\n"); valid = 0; } } } choice = atoi(iobuf); return choice; } int submenu(void) { char iobuf[80]; int choice2; int i,len,valid; //HANDLE hProcess; PROCESS_INFORMATION pi; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ HANDLE hProcess; DWORD lpAddr = 0; TCHAR lpApplicationName[_MAX_PATH]=""; int result; char ans [4]=""; //int choice; printf ("\n*****************************************\n"); printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n"); printf ("========================================="); printf ("\n=\t 1: Suspend the process\t\t="); printf ("\n=\t 2: Resume process \t="); printf ("\n=\t 3: Shutdown the process \t="); printf ("\n=\t 4: Exit the system \t="); printf ("\n=========================================\n"); printf ("\n"); valid=0; printf("\nEnter choice (1-4): "); while( valid == 0) { fgets(iobuf,sizeof(iobuf),stdin); // remove '\n' len = strlen(iobuf)-1; iobuf[len] = 0;
I still think that you should have gone with my suggestion - which was to have one menu and only show valid options. Where does it crash ? Perhaps if you posted the full code ( at the moment, what you're including is missing ), someone will post it into a project and try to work out what's going wrong, but it would be more helpful if you told us. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
I still think that you should have gone with my suggestion - which was to have one menu and only show valid options. Where does it crash ? Perhaps if you posted the full code ( at the moment, what you're including is missing ), someone will post it into a project and try to work out what's going wrong, but it would be more helpful if you told us. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
Well i wanted to go with your suggestion but then i have the program crushing and i have already intergrated my code it is now large. But even the submenu one that i am thinking above cannot confuse user's of the system if it is used. -oam-
First trick of programming - if it crashes, work out why, don't just change to a lesser design :-) To reiterate - where/why does it crash ? I assume that crush == crash ? Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
First trick of programming - if it crashes, work out why, don't just change to a lesser design :-) To reiterate - where/why does it crash ? I assume that crush == crash ? Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
Christian Graus wrote: First trick of programming - if it crashes, work out why, don't just change to a lesser design Yes i am working on it day and night but now i am under presure as i have to submit this tommorrow.
#include #include #include #include #include typedef struct _iobuf FILE; #include #include #include #include int menu(void) { //int choice; char iobuf[80]; int i,len,valid; HANDLE hProcess; printf ("\n"); printf ("\t\t\t*****************************************\n"); printf ("\t\t\t*\t\t\t\t\t*\n\t\t\t*\t\tPROCESS\t\t\t*\n"); printf ("\t\t\t*\t\t\t\t\t*\n\t\t\t* CHECKPOINTING AND MIGRATION SYSTEM\t*\n"); printf ("\t\t\t*\t\t\t\t\t*\n"); printf ("\t\t\t========================================="); printf ("\n\t\t\t=\t 1: Create a Process \t="); printf ("\n\t\t\t=\t 2: Suspend Process \t="); printf ("\n\t\t\t=\t 3: Resume Process \t="); printf ("\n\t\t\t=\t 4: Shutdown Process\t\t="); printf ("\n\t\t\t=\t 5: Checkpoint Process\t\t="); printf ("\n\t\t\t=\t 6: Restart Process\t\t="); printf ("\n\t\t\t=\t 7: Help \t\t\t="); printf ("\n\t\t\t=\t 8: Quit the system\t\t="); printf ("\n\t\t\t=========================================\n"); printf ("\n"); printf("\n\t\t\tEnter choice (1-8): "); valid = 0; while( valid == 0) { fgets(iobuf,sizeof(iobuf),stdin); len = strlen(iobuf)-1; iobuf[len] = 0;// the input/output buffer for storing characters // validate data valid = 1; // assume valid input for(i = 0; i < len; i++) //loop controlling invalid input { if( !isdigit(iobuf[i])) { printf("\n\t\t\tPlese enter numeric digits only (1-8):"); valid = 0; } } }//while hProcess = atoi(iobuf); return hProcess; }//menu HWND g_hWnd = NULL; BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam) { DWORD dwProcID; GetWindowThreadProcessId(hwnd,&dwProcID); if(dwProcID == (DWORD)lParam) { //this hwnd is the top level window ofthe process g_hWnd = hwnd; } return TRUE; } int main(int argc, char **argv) { FILE* fp; //char fname[20]; char ans[4]; int result; PROCESS_INFORMATION pi; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ HANDLE hProces
-
Christian Graus wrote: First trick of programming - if it crashes, work out why, don't just change to a lesser design Yes i am working on it day and night but now i am under presure as i have to submit this tommorrow.
#include #include #include #include #include typedef struct _iobuf FILE; #include #include #include #include int menu(void) { //int choice; char iobuf[80]; int i,len,valid; HANDLE hProcess; printf ("\n"); printf ("\t\t\t*****************************************\n"); printf ("\t\t\t*\t\t\t\t\t*\n\t\t\t*\t\tPROCESS\t\t\t*\n"); printf ("\t\t\t*\t\t\t\t\t*\n\t\t\t* CHECKPOINTING AND MIGRATION SYSTEM\t*\n"); printf ("\t\t\t*\t\t\t\t\t*\n"); printf ("\t\t\t========================================="); printf ("\n\t\t\t=\t 1: Create a Process \t="); printf ("\n\t\t\t=\t 2: Suspend Process \t="); printf ("\n\t\t\t=\t 3: Resume Process \t="); printf ("\n\t\t\t=\t 4: Shutdown Process\t\t="); printf ("\n\t\t\t=\t 5: Checkpoint Process\t\t="); printf ("\n\t\t\t=\t 6: Restart Process\t\t="); printf ("\n\t\t\t=\t 7: Help \t\t\t="); printf ("\n\t\t\t=\t 8: Quit the system\t\t="); printf ("\n\t\t\t=========================================\n"); printf ("\n"); printf("\n\t\t\tEnter choice (1-8): "); valid = 0; while( valid == 0) { fgets(iobuf,sizeof(iobuf),stdin); len = strlen(iobuf)-1; iobuf[len] = 0;// the input/output buffer for storing characters // validate data valid = 1; // assume valid input for(i = 0; i < len; i++) //loop controlling invalid input { if( !isdigit(iobuf[i])) { printf("\n\t\t\tPlese enter numeric digits only (1-8):"); valid = 0; } } }//while hProcess = atoi(iobuf); return hProcess; }//menu HWND g_hWnd = NULL; BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam) { DWORD dwProcID; GetWindowThreadProcessId(hwnd,&dwProcID); if(dwProcID == (DWORD)lParam) { //this hwnd is the top level window ofthe process g_hWnd = hwnd; } return TRUE; } int main(int argc, char **argv) { FILE* fp; //char fname[20]; char ans[4]; int result; PROCESS_INFORMATION pi; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ HANDLE hProces
I keep hoping that at some point you will either check the 'Do not treat <'s as HTML tags' box so that your includes come out in your post, or you'll stop just posting all the code over and over, and actually tell us what's going wrong/what error messages you get/etc. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
I keep hoping that at some point you will either check the 'Do not treat <'s as HTML tags' box so that your includes come out in your post, or you'll stop just posting all the code over and over, and actually tell us what's going wrong/what error messages you get/etc. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
Error 1: It does not validate properly: option 2-6 should not run before option 1. All these option crushes the program Error 2: It executes the default of the case statement if the user enter "no" if does not want to shutdown the program -oam-
Error 1 I explained to you at length last week. If you're unable to pass the handle to process you're creating to the menu function and print/validate the menu choice based on this input, you probably *should* fail this time around, and learn some basic coding before you start creating processes. Error 2 - I don't understand. It won't shut down if you type 'y' ? Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
Error 1 I explained to you at length last week. If you're unable to pass the handle to process you're creating to the menu function and print/validate the menu choice based on this input, you probably *should* fail this time around, and learn some basic coding before you start creating processes. Error 2 - I don't understand. It won't shut down if you type 'y' ? Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
Christian Graus wrote: Error 2 - I don't understand. It won't shut down if you type 'y' ? If i choose optio 8, it will output; Are you sure you want to quit the system(y or n): n if no is entered then the output is "You have entered an invalid command, check the menu below" and displays menu instead it should display the menu only -oam-