473,387 Members | 1,844 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.

nested structs

1
Please help...i have the following code:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <pthread.h>
  5. #include <time.h>
  6. #include <sys/time.h>
  7. #include <string.h>
  8.  
  9. typedef int ProID;
  10. struct proDes {
  11.    struct proDes *next;
  12.    struct proDes *prev;
  13.    char name[10];
  14.    ProID pid;
  15.    int priority;
  16.    long waittime;
  17.    struct intHeap *heap;
  18.    struct LL *inlist;
  19. };
  20.  
  21. struct intHeap{
  22.    struct intHeap *ndata;
  23.    char *dataname;
  24.    int value;
  25. };
  26.  
  27.  
  28. typedef enum{RUNNING, READY, L_DYING} ListType;
  29. struct LL{
  30.    struct proDes *head;
  31.    ListType type;
  32. };
i would like to create a linked-list using the pointer *inlist, how do i access it?
*NB: i have a linked list *lnode and want to sort its elements according to
waittime saving the sorted list in the new linked-list, inlist.


I tried this:
Expand|Select|Wrap|Line Numbers
  1. lnode->inlist->head = (struct proDes *)malloc(sizeof(struct proDes));
but it gives me a segmentation fault when i run it.
Oct 14 '07 #1
2 2994
Ganon11
3,652 Expert 2GB
You have a circular pointer embedded in your structure. Your LL struct contains a pointer to the head of a linked list, which is of type proDes. But the proDes struct has a pointer to a LL. Is this necessary?

I'm not sure if this is giving you the error, but it seems a little strange to me as a design point.
Oct 14 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
I might suggest that you separate your linked list from your proDes struct on the off chance that you might want a linked list of something else later on and won't be able to reuse any of your code.

That would force rewriting and debugging the linked list all over again.

Do this:

1) Make your node data independent:

Expand|Select|Wrap|Line Numbers
  1. struct Node
  2. {
  3.     void* the Data;
  4.     Node* next;
  5.     Node* prev;
  6. };
  7.  
2) Now get your linked list working. Use an int for starters and put the address of the int in the Node as the pointer to theData. This is a C solution. C++ already has the the linked list written for you.

3) Make sure your linked list code is in files that do not contain main(). Otherwise, you won't be able to use the files in another program.

4) Once the linked list works with ints, use the linked list files in anotrher program where you store the address o a proDes variable in the Node.
Oct 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Matthew Barnes | last post by:
I was wondering if there would be any interest in extending the struct.unpack format notation to be able to express groups of data with parenthesis. For example: >>> data =...
0
by: Alexandros__ | last post by:
Hello everyone, I am using the Configuration Application block to write an XML configuration file for my application. Most of it is working fine but I have a problem serialising some nested...
9
by: Joolz | last post by:
Could someone please give me an example of how to make pointers to nested structures? Pointers to normal structures are no problem... struct structA { int a; }structA_s; structA *pStructA =...
10
by: nimmi_srivastav | last post by:
Below you will see an example of a nested conditional expression that this colleague of mine loves. He claims that it is more efficient that a multi-level if-else-if structure. Moreover, our...
6
by: jwvai316 | last post by:
I don't really know how to say it so I just say it a nested linklist. How do you make LinkLists inside LinkList? Can anyone help me for this? I think an example program will help me a lot. ...
4
by: Christopher Ireland | last post by:
Hi -- I'm trying to find an example of a nested class implemented within the .NET Framework itself but without much success. I don't suppose that anybody knows of such an example off the top of...
0
by: Kurt Ng | last post by:
Need help quick!!! Am really stuck on this problem! I have a C dll, and it uses a nested struct. (see below) The struct has 2 layers of nested structs. The first field in the first struct is...
4
by: MSDousti | last post by:
Hi all, I read some Q&As in the Net, discussing Marshalization of nested structs in C# (or VB.NET). Some guys stated that .NET framework does not support this feature yet. Are they right? ...
9
by: Bill Grigg | last post by:
All, Can anyone supply an example or reference to an example of using reflection to determine the data types and array lengths contained in a nested stucture in C#? Actually, it is a structure...
8
by: Sheldon | last post by:
Hi, Can anyone help with this problem with setting up nested structures and initializing them for use. I have created several structs and placed them in a super struct that I will then pass to...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.