Search
 
SCRIPT & CODE EXAMPLE
 

C

best approach c menu terminal

#include<stdio.h>

typedef void (*Menu_Processing_Function_Pointer)(void);

struct Menu_Option
{
	char choice;
	char const *p_selection_text;
	Menu_Processing_Function_Pointer p_processing_function;
};

void Process_Selection_One(){
	printf("Test one
");
};
void Process_Selection_Two(){
	printf("Test two
");
};

struct Menu_Option main_menu[] =
	{
		{'1', "Option 1", Process_Selection_One},
		{'2', "Option 2", Process_Selection_Two},
};
static const size_t quantity_selections =
	sizeof(main_menu) / sizeof(main_menu[0]);

int main(){
	printf(
		"
"
		"------------------------------
"
		"         Main Menu
"
		"------------------------------
"
	);
	for (size_t i = 0; i < quantity_selections; i++) {
		printf("%li:	%s
", i+1, main_menu[i].p_selection_text);
	}
	printf("Enter selection, 0 to quit: ");
	char choice;
	scanf("%c", &choice); 
	for (size_t i = 0; i < quantity_selections; ++i) {
		if (choice == main_menu[i].choice) {
			Menu_Processing_Function_Pointer p_function = main_menu[i].p_processing_function;
			(p_function)();
			break;
		}
	}
	return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: Float and Double Input/Output 
C :: how to merge 2 bytes into an integer 
C :: c language 
C :: pyinstaller hidden import tensorflow not found 
C :: choose random number with weight 
C :: why do you jerk while falling aslee 
C :: c check if character is upper case 
C :: -42 c to f 
C :: print in c 
C :: rust set toolchain 
C :: array of strings c 
C :: c unused parameter 
C :: majuscule en c 
C :: pointer c 
C :: files in c programming 
C :: C #ifdef Directive 
C :: columntransformer in randomizedsearchcv 
C :: c get int inpot 
C :: how to find adam number uasing loop in C 
C :: install lib juicyPixel in haskell 
C :: npm fs zip 
C :: C Program to Maintain an Inventory of items in Online Store 
C :: ESP32 timerBegin(0, cpuClock, true); 
C :: Uri/beecrowd problem no - 1099 solution in C 
C :: Letters and Digits Total 
C :: get file ligne count c 
C :: fgets langage c 
C :: float and double Output 
C :: comando para ejecutar hilos en c 
C :: write to file in c programming 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =