473,473 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Challenging Logic

Hi,
I am new to c language and i have a problem to solve. Imagine a
parent child relationship let me take menu as an example

File Edit
New Cut
Window Copy
Message
Open

here File and Edit are Top Level Parents(root menu), New and Open are
children of File. Window and MEssage are children of NEw. Similarly
Cut and Copy are children of Edit.

I can have only 2 functions like Next and GetSubMenu. Initially i will
display File when i say next it should show me edit when i say next it
should show me file.

When i am in File when is say get submenu it should display new and
now next should give me open and next should take me to File since
Open is the last child of File. Similary when i am in New and say
GetSubMenu it should give me Window and Next should give me Message
and Next should give me New.

I dont know whether i need to use a bidirectional circular linked list
or array. i need some help from you.

Thanks.
Jun 27 '08 #1
2 1331
"Nash" <je******@gmail.comwrote in message
news:63**********************************@i18g2000 prn.googlegroups.com...
Hi,
I am new to c language and i have a problem to solve. Imagine a
parent child relationship let me take menu as an example

File Edit
New Cut
Window Copy
Message
Open

You can make a simplistic model of this with an array, linked-list and two
data-structures...

#define ITEMS_PER_MENU 16
#define ITEM_NAME_SIZE 16
#define MENU_NAME_SIZE ITEM_NAME_SIZE

struct item {
char name[ITEM_NAME_SIZE];
struct menu* child;
};

struct menu {
char name[MENU_NAME_SIZE];
size_t items;
struct item items[ITEMS_PER_MENU];
};

static struct menu my_file_new_submenu = {
{ "File::New" }, 2,
{ { "Window" }, NULL },
{ { "Message" }, NULL }
};

static struct menu my_file_menu = {
{ "File" }, 2,
{ { "New" }, &my_file_new_submenu },
{ { "Open" }, NULL }
};

static struct menu my_edit_menu = {
{ "Edit" }, 2,
{ { "Cut" }, NULL },
{ { "Copy" }, NULL }
};
[...]

Jun 27 '08 #2

"Chris Thomasson" <cr*****@comcast.netwrote in message
"Nash" <je******@gmail.comwrote in message
news:63**********************************@i18g2000 prn.googlegroups.com...
>Hi,
I am new to c language and i have a problem to solve. Imagine a
parent child relationship let me take menu as an example

File Edit
New Cut
Window Copy
Message
Open


You can make a simplistic model of this with an array, linked-list and two
data-structures...

#define ITEMS_PER_MENU 16
#define ITEM_NAME_SIZE 16
#define MENU_NAME_SIZE ITEM_NAME_SIZE

struct item {
char name[ITEM_NAME_SIZE];
struct menu* child;
};

struct menu {
char name[MENU_NAME_SIZE];
size_t items;
struct item items[ITEMS_PER_MENU];
};

static struct menu my_file_new_submenu = {
{ "File::New" }, 2,
{ { "Window" }, NULL },
{ { "Message" }, NULL }
};

static struct menu my_file_menu = {
{ "File" }, 2,
{ { "New" }, &my_file_new_submenu },
{ { "Open" }, NULL }
};

static struct menu my_edit_menu = {
{ "Edit" }, 2,
{ { "Cut" }, NULL },
{ { "Copy" }, NULL }
};
[...]
A better way to solve the problem is to think linked lists.

struct node
{
struct node *next;
struct node *child;
char label[64];
void *ptr; /* for later use */
};

Now we can have an arbitrary menu system, with the first File entry at the
root. Allocate all the nodes using malloc().
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: George | last post by:
Was my question too challenging for everyone? I thought I would get a much quicker response, complete with witty and (sometimes) condescending remarks Here's my question again, in case you missed...
18
by: Frankie | last post by:
I have been hired to go to a former client of mine and train their staff programmers on ASP.NET. These guys have only Mainframe, MS Access, SQL Server, and VB6 desktop application development...
0
by: Al Fatykhov | last post by:
Using MABLE logic engine with existing .NET applications. MABLE web services provide an interface to MABLE business objects and logic. Let us review some technical details of the MABLE web...
0
by: Wim Vanhoof | last post by:
----------------------------------------------------------- WLPE' 06 - CALL FOR PAPERS Workshop on Logic-based Methods in Programming Environments (satellite workshop of ICLP’06) August...
5
by: alainpoint | last post by:
Hi, I have what in my eyes seems a challenging problem. Thanks to Peter Otten, i got the following code to work. It is a sort of named tuple. from operator import itemgetter def...
16
by: MS newsgroup | last post by:
I don't have clear reasons why we need business logic layer and data logic layer instead of having only data logic layer. Are there any good reasons for that?
0
by: fiona | last post by:
FOR IMMEDIATE RELEASE Catalyst release low cost logic processing tool 87% of defects in software are errors in logic Yucca Valley, CA, September 2006 - Catalyst Development Corporation,...
14
by: rabbitrun | last post by:
Hi Everyone, I work for a financial company. I am planning to give a presentation to rest of the development team (15 people) here on moving server side logic to client-side javascript for an...
9
by: SAL | last post by:
Hello, I have a Dataset that I have table adapters in I designed using the designer (DataLayer). I have a business logic layer that immulates the DataLayer which may/may not have additional logic...
15
by: bruno.desthuilliers | last post by:
On 27 juin, 18:09, "John Salerno" <johnj...@NOSPAMgmail.comwrote: For which definitions of "content" and "logic" ??? The point of mvc is to keep domain logic separated from presentation logic,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.