473,387 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1329
"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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.