i have these structures in my program,
typedef struct Loading {
char **name; // Name of the program
int pid; // current pid of the program
struct Loading *prec;
struct new_phrase *line;
} Loading ;
typedef struct {
int N; // number of words
char **T; // words stored in an array
} new_phrase;
i want to initialize N through line in the structure Loading.
i dont know how to do that.
i thought of something like (*load).(*line).N=45;
while having
Loading *load;
any suggestions?
|
|
0
|
|
|
|
Reply
|
chitlesh1 (22)
|
6/12/2005 2:51:55 PM |
|
Clunixchit wrote:
> i have these structures in my program,
>
> typedef struct Loading {
> char **name; // Name of the program
> int pid; // current pid of the program
> struct Loading *prec;
> struct new_phrase *line;
> } Loading ;
>
> typedef struct {
> int N; // number of words
> char **T; // words stored in an array
> } new_phrase;
>
> i want to initialize N through line in the structure Loading.
> i dont know how to do that.
> i thought of something like (*load).(*line).N=45;
> while having
> Loading *load;
>
> any suggestions?
The `line' element of your `struct Loading' is a pointer
to a `struct new_phrase', but the compiler does not know what
a `struct new_phrase' contains -- in particular, it does not
know whether it contains an element named `N', nor what type
that element might be. This is because you have not declared
the `struct new_phrase' type anywhere.
Look carefully at the second declaration: it declares an
"anonymous" struct type and declares `new_phrase' as an alias
for that anonymous type. Either change the second declaration
to look like the first (so `struct new_phrase' is known), or
else change the type of `line' from `struct new_phrase*' to
`new_phrase*' (and put the second declaration first so that
`new_phrase' is declared before it's used.)
Once you've done this, rewrite the assignment statement
as `load->line->N = 45;'. `(*(*load).line).N = 45;' would
also work, but is clumsier.
--
Eric Sosman
esosman@acm-dot-org.invalid
|
|
0
|
|
|
|
Reply
|
esosman (1335)
|
6/12/2005 3:30:50 PM
|
|
> Eric Sosmanwrote:
Clunixchit wrote:
>
> Either change the second declaration
> to look like the first (so `struct new_phrase' is known), or
> else change the type of `line' from `struct new_phrase*' to
> `new_phrase*' (and put the second declaration first so that
> `new_phrase' is declared before it's used.)
>
> Once you've done this, rewrite the assignment statement
> as `load->line->N = 45;'. `(*(*load).line).N = 45;' would
> also work, but is clumsier.
>
im using 3 files for my program.
first is the main function where i wrote load->line->N = 45;
in the second, there is the new_phase structure
the last one contains the Loading structure
hence how can i declare new_phrase before the Loading structure ?
my main:
new_phrase phrase;
Loading *Load = NULL;
|
|
0
|
|
|
|
Reply
|
chitlesh1 (22)
|
6/12/2005 4:07:12 PM
|
|
Clunixchit wrote on 12/06/05 :
> i have these structures in my program,
<...>
Stay simple. define things before using them :
typedef struct
{
/* number of words */
int N;
/* words stored in an array */
char **T;
}
new_phrase;
typedef struct Loading
{
/* Name of the program */
char **name;
/* current pid of the program */
int pid;
struct Loading *prec;
new_phrase *line;
}
Loading;
int main (void)
{
Loading x =
{0, 0, 0, 0};
new_phrase y =
{0, 0};
x.line = &y;
x.line->N = 123;
return 0;
}
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html
"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++
|
|
0
|
|
|
|
Reply
|
emdel (952)
|
6/12/2005 6:19:58 PM
|
|
|
3 Replies
38 Views
(page loaded in 0.06 seconds)
Similiar Articles: "TYPEDEF PTR with STRUCT" masm32 - comp.lang.asm.x86 ...Hello. My problem: I have a struct and a function with a pointer to the struct as parameter. But the following program code causes an error: "error A... initializing embedded anonymous struct static members? - comp.lang ...///// snippet ///// struct t { static struct { } a; }; struct { } t::a; int main(void) { } ///// snippet /////... compare struct in6_addr - comp.unix.programmerhow does one compare a struct in6_addr? can i just memcmp() the s6_addr member, as i would do the s_addr member from a struct in_addr? tia, Bill ... create a struct in mexFunction - comp.soft-sys.math.scilab ...hi, in mexFunction(int nlhs,mxArray *plhs[],int nrhs, const mxArray *prhs []){}, i tried to create a struct in another struct, but finally i got ... struct/union difference - comp.lang.c++.moderatedC++ treats the members of an unnamed, untagged local union as variables of the scope which encloses the union, as below: int main() { union ... struct with const member variable without explicit constructor ...Hi. Is the following code c++: typedef struct { int a; int const b; } C; The Intel compiler gives the following warn... Global Variable vs Struct Variable Question - comp.lang.asm.x86 ...I have read Pentium IV Optimization manual that it explains to avoid global variable because it is slow. MOV instruction has to direct memory a... How to make struct from workspace available in m-file s-function ...Hey everybody, I'm evaluating a function expression by using a m-file s-function within my simulink model. Therefore I offline calculate a coefficient structure and ... help needed for a grep in a multidimensional struct array - comp ...Hi, I have the following problem. I have the following variable: slot = 30x5x10 struct array with fields: modulo cdl I need to... forward declaration of 'struct::Class' - comp.lang ...forward declaration of 'struct::Class' - comp.lang ... When Full Declarations Are Not Required First, you can only give a forward declaration for the actual type of a ... struct (C programming language) - Wikipedia, the free encyclopediaA struct in C programming language is a structured (record) type that aggregates a fixed set of labelled objects, possibly of different types, into a single object. Create structure array - MATLAB - MathWorks - MATLAB and Simulink ...This MATLAB function creates a structure array with the specified fields and values. struct (C++)The struct keyword defines a structure type and/or a variable of a structure type. Class: Struct (Ruby 1.9.3)A Struct is a convenient way to bundle a number of attributes together, using accessor methods, without having to write an explicit class. The Struct class is a ... STRUCT keyword - LIXStructure basics struct is used to declare a new data-type. Basically this means grouping variables together. For example, a struct data type could be used to declare ... 6/22/2012 2:19:27 AM
|