linked list in C
OK!
I declare few nodes . lets say my node is named as sortElement.
now I want to store the memory locations of these nodes in an array
How do i declare that?
I tired something this way but I encountered an error in linux
struct sortElement
{
declaration;
};
sortElement *element[24];
what i am trying to do here is declare an array element which can store the locations of all my nodes
will this work?
I declare few nodes . lets say my node is named as sortElement.
now I want to store the memory locations of these nodes in an array
How do i declare that?
I tired something this way but I encountered an error in linux
struct sortElement
{
declaration;
};
sortElement *element[24];
what i am trying to do here is declare an array element which can store the locations of all my nodes
will this work?
Replies
-
Corpse-ThrustI guess C doesn't support creating pointers to custom data types. Only C++ does.
Try creating a pointer of type void and using it to store the memory locations of the nodes. -
pradeep_agrawal
C language do support creation of pointers to user defined data type. Below is one of the CE posts where i have defined pointer to user defined data type in C:Corpse-ThrustI guess C doesn't support creating pointers to custom data types. Only C++ does.
#-Link-Snipped-#
The above code will not work due to two reasons:durgaI declare few nodes . lets say my node is named as sortElement.
now I want to store the memory locations of these nodes in an array
How do i declare that?
I tired something this way but I encountered an error in linux
struct sortElement
{
declaration;
};
sortElement *element[24];
what i am trying to do here is declare an array element which can store the locations of all my nodes
will this work?
1. The declaration inside the body of struct should be a valid variable declaration (e.g., "int declaration;").
2. You are trying to create an array of pointers to sortElement, but sortElement is not a valid data type. The valid type is "struct sortElement" or you need to define a data type using typedef.
The declaration should be as:
struct sortElement { int declaration; //or something else as required }; struct sortElement *element[24];
or
typedef struct { int declaration; //or something else as required } sortElement_t; sortElement_t *element[24];
Let us know if you face issue with above change.
-Pradeep -
durga chHi CT, Pradeep,
Thanks for the reply.
Firstly 'declaration' is not my variable. I have list of declarations and I did do typedef
The actual code is as below:
typedef struct sortElement sortElement;
struct sortElement
{
int elementnumber;
int topflag;
int bottonflag;
sortElement *zero;
sortElement *one;
struct inputbuf1;
struct inputbuf2;
struct outputbuf1;
struct outputbuf2;
};
sortElement *element[24]; -
pradeep_agrawalAs you are declaring correct variables inside the body of struct so there is only one issue is the declaratio
sortElement *element[24];
is not correct. The declaration should be as:
struct sortElement { //variable declaration }; struct sortElement *element[24];
or
typedef struct { //variable declaration } sortElement_t; sortElement_t *element[24];
Let us know if you face issue with above change.
-Pradeep -
durga chthanks! But what is wrong with "typedef struct sortElement sortElement;"
is it not same as saying take "struct sortElement" as sortElement?
P.S: I have few more syntax related questions to ask, is it OK if I continue int his thread?
Thansk again! -
pradeep_agrawal
When we declare a struct asdurgathanks! But what is wrong with "typedef struct sortElement sortElement;"
is it not same as saying take "struct sortElement" as sortElement
struct structName { //declaration of variables };
The declaration of variable of the above type will look like:
struct structName xyz;
As per C syntax you can not declare a variable as "structNamexyz ;" because structName is currently not a data type "struct structName" is a data type.
'typedef' can be used to define a data type to avoid using 'struct' with 'structName' while you are declaring variables.
The typedef will look like:
typedef struct structName { //variable declaration } structName_t;
Here i have defined a data type structName_t of type "struct structName". Now you can use "structName_t" instead of "struct structName".
The declaration of variable using the newly defined data type can be done as:
structName_t xyz;
Let me know if any item need more clarification.
P.S.: For query on different topic start new thread.
-Pradeep -
durga chgot it! thanks for that
You are reading an archived discussion.
Related Posts
Hello Ceans!!!
Is there any Electronics Expo or Fair in June? if there is not then in July
please let me know if there is any one
Thanks in Advanced...
Engineers who own startups, wannabe entrepreneurs & anyone interested in cool technology -
Silicon India has organized Startup City 2009 at Nimhans Convention Center in Bangalore on June 6th, 2009....
Hey am a third year electrical engineering student,working on ideas to start a project. I've found this one..how will i start a project on fault control for a switching network...
i am doing my 1st year engineering.suggest me few interesting topics that i can work on for my paper presentation.
can some1 plz help me on eigen tracking
like i dont kno anything about that
and i have a project on digital video object tracking
so help me by giving...