473,320 Members | 1,732 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,320 software developers and data experts.

linked list related

Hi aal,
I am trying to draw different shapes in BREW MP. it’s a mob OS by Qualcomm. The programming is in C.
The operation is I’ve to draw different shapes on screen based on the selected button. But before drawing the next shape I need to store the values of old shapes which I had drew. So I need to maintain data structure for each shapes. When I press particular button(say circle) after drawing that circle values need to be stored in linked list before drawing next shape.

I’ve taken a linked list after drawing each shape add it as a node to linked list then before calling new shape traverse this list n draw all available shapes.

for that i've bulit union inside a structure with type_def

Expand|Select|Wrap|Line Numbers
  1. struct shapes{
  2.           int type_in_union;
  3.            union draw{
  4.            struct line lines;
  5.            struct ellipse ellipses;
  6.            struct rect rects;
  7.            struct polygon polygons;
  8.  
  9.                  }draw;
  10. }shapes1;
  11.  
  12.  
  13.  
  14.  
  15. struct line{
  16. int sx,sy;
  17. int ex,ey;
  18. }line;
  19.  
  20. struct ellipse{
  21. int cx,cy;
  22. int wx;
  23. int wy;
  24. }ellipse;
  25.  
  26. struct rect{
  27. int x,y;
  28. int dx,dy;
  29. }rect;
  30.  
  31. struct polygon{
  32. int len;
  33. struct point *points;
  34. }poly;
  35.  
  36. struct point{
  37. int x,y;
  38. }points;
  39.  
  40.  


now i want to dump after each operation(each shape ) that structure into the linked list so that when next time before drawing any new shape i can call all the previous shapes i had drew using linked list .

for this i've declared a liked list

Expand|Select|Wrap|Line Numbers
  1. struct Node{
  2. struct shapes *shape;
  3. struct Node *pNext; 
  4. struct Node *pPrev;
  5. int type;
  6. };
  7.  

I am Trying to create nodes of structure

Expand|Select|Wrap|Line Numbers
  1. insert_node(create_node(&shape_type,&a,&b,&x,&y));
  2.  
  3. void insert_node(struct Node *pNode)
  4. {
  5.  
  6.         struct Node *t;
  7.         struct Node *pTemp = NULL;
  8.         if(pStart == NULL)
  9.         {
  10.         pStart = pNode;   /* Store address of the node as the start node */
  11.         return;
  12.         }
  13.         else
  14.         {
  15.             t=pStart;
  16.             while(t->pNext!=NULL)
  17.             {
  18.                 t=t->pNext;
  19.              }
  20.                  t->pNext=pNode;
  21.                 pNode->pPrev=t;
  22.          }
  23. }
  24.  
  25. struct Node* create_node(int *shape_type,int *a,int *b,int *x,int *y)
  26. {
  27.   struct Node *pNode = NULL;                         // Pointer to the new node                 
  28.   pNode = (struct Node*)malloc(sizeof(struct Node)); // Allocate memory for node                
  29.   pNode->pNext = NULL;                               // No next node yet                        
  30.   pNode->pPrev = NULL;                                 // No previous node
  31.   pNode->type=*shape_type;
  32.   pNode->shape = create_record(&shape_type,&a,&b,&x,&y); // Create record and store address in node 
  33.   return pNode;
  34. }
  35.  

create_record function


Expand|Select|Wrap|Line Numbers
  1.  
  2. struct shapes*  create_record(int *shape_type,int *a,int *b,int *x,int *y)
  3. {
  4.     struct shapes *shape=NULL;
  5.  
  6.     if(*shape_type==LINE)
  7.     {
  8.     //struct shapes *shape=NULL;
  9.     shape = (struct shapes*)malloc(sizeof(struct shapes)); 
  10.     shape->draw.lines=createline(&shape_type,&a,&b,&x,&y);
  11.     }
  12.         return shape;
  13.  
  14. }
  15.  
  16.  
createline function

Expand|Select|Wrap|Line Numbers
  1. struct line* createline(int *shape_type,int *a,int *b,int *x,int *y)
  2. {
  3.     struct line *line1=NULL;
  4.     line1 = (struct line*)malloc(sizeof(struct line));
  5.     line1->start_x=*a;
  6.     line1->start_y=*b;
  7.     line1->end_x=*x;
  8.     line1->end_y=*y;
  9.     return line1;
  10. }
  11.  
  12.  
Is It Right way to store the things into structures???????????
n also i wantt to retrieve the things how it can be done....??????
Dec 17 '10 #1
5 2299
weaknessforcats
9,208 Expert Mod 8TB
I suggest you write a main(). Create a struct variable and create ints f various values. Then add the values to the struct variable. Next use printf to display the values you put in the variable.

Remember that you use the "." operator for struct variable members when you use the variable name and the "->" operator for the members when you use the address of a struct variable.
Dec 17 '10 #2
HI,
There is no main in this BREW SDK man... Its not giving any compilation error but giving error during run time..:(
Dec 21 '10 #3
weaknessforcats
9,208 Expert Mod 8TB
Then you probably have a bad pointer value.

I suggest you step through the code using your debugger. When you find the line that fails and you can't fix it, then post again.
Dec 21 '10 #4
donbock
2,426 Expert 2GB
Probably not your problem, but you should always check if malloc failed.
Dec 21 '10 #5
Hey now its working fine ..:) Thanks for the Replies:)
Dec 22 '10 #6

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

Similar topics

7
by: Chris Ritchey | last post by:
Hmmm I might scare people away from this one just by the title, or draw people in with a chalange :) I'm writting this program in c++, however I'm using char* instead of the string class, I am...
7
by: dam_fool_2003 | last post by:
friends, I wanted to learn the various ways of inserting a single list. so: Method 1: #include<stdlib.h> #include<stdio.h> struct node { unsigned int data; struct node *next;
7
by: Kieran Simkin | last post by:
Hi all, I'm having some trouble with a linked list function and was wondering if anyone could shed any light on it. Basically I have a singly-linked list which stores pid numbers of a process's...
12
by: Jonathan Bartlett | last post by:
Just finished a new IBM DeveloperWorks article on linked lists, and thought you all might be interested. It's not an introduction -- it instead covers some of the more interesting aspects of...
57
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
19
by: Dongsheng Ruan | last post by:
with a cell class like this: #!/usr/bin/python import sys class Cell: def __init__( self, data, next=None ): self.data = data
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
2
by: Chris Thomasson | last post by:
I was wondering if the 'SLINK_*' and 'SLIST_*' macros, which implement a simple singly-linked list, will produce _any_ possible undefined behavior: ____________________________ #include...
6
by: dmp | last post by:
Where can I find programs related to linked list.
12
by: kalyan | last post by:
Hi, I am using Linux + SysV Shared memory (sorry, but my question is all about offset + pointers and not about linux/IPC) and hence use offset's instead on pointers to store the linked list in...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.