ncurses menu

closed account (Dy7SLyTq)
im making a menu in ncurses for a console application. im not near a compiler so could someone please verify that my code is right. if there is an error please tell me how to fix it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

void menu(string &menuChoice)
{
	char *choices[] = {"Create Account", "Load Account", "Options", "Exit"};
	char currentChar;
	ITEM **itemList;
	ITEM *cur_item;
	int counter, choicesSize;				
	MENU *menu;

	choicesSize = (sizeof(choices) / sizeof(choices[0]))
	itemList = (ITEM **)calloc(choiceSize + 1, sizeof(ITEM *));

	for(counter = 0; counter < choiceSize; counter = counter + 1)
		itemList[counter] = new_item(choices[counter], choices[counter]);

	itemList[choiceSize] = (ITEM *)NULL;

	menu = new_menu((ITEM **)itemList);
	post_menu(menu);
	refresh();

	while(currentChar = getch())
	{
		switch(currentChar)
		{
			case KEY_DOWN:
			        menu_driver(menu, REQ_DOWN_ITEM);
				break;

			case KEY_UP:
				menu_driver(menu, REQ_UP_ITEM);
				break;

			case '\n':
				menuChoice = (menu, REQ_TOGGLE_ITEM);
		}
	}	

	free_item(my_items[0]);
	free_item(my_items[1]);
	free_menu(my_menu);
	endwin();
}


my main concern is:
case '\n':
menuChoice = (menu, REQ_TOGGLE_ITEM);

is that the right way to get the current option?
Im no expert and i just started to look at ncurses..

I was wondering, what does this do??

choicesSize = (sizeof(choices) / sizeof(choices[0]))

choisesSize = 5 / 13 ( will result in choisesSize = 0)?

Please correct me if im wrong.

Any how, you missed a semicolon on that line. :P

Have a great day! /swe-noob :)
closed account (Dy7SLyTq)
tyeah ur right about the semicolon i havent tried to compile it yet. as to the others: i copied this code and changed it around because i dont know how to build it from scratch
Where's initscr()? You need that before you can use ncurses I believe.
closed account (Dy7SLyTq)
i know. its called in main before menu. and i dont know why end win() is in there
Topic archived. No new replies allowed.