natman said:
Hi i need to write a funcition called install, its takes as arguments
1- a vector
2-a number
3-a list called next_level
so heres where it get kinda weird:
next_level is a list comprising of elements that are { vectors, with
pointers}, defined by the following struct
typedef struct wnode {
int weight[maxrank+1];
struct wnode *next;
} WEIGHTPTR,*WEIGHTPTR;
I doubt that. You've defined WEIGHTPTR twice, once as an alias for
your struct, and again as an alias for a pointer to your struct.
Presumably maxrank is a macro for some integer constant. As a matter
of style, it should be in all-caps: MAXRANK.
Indentation is important if you want your code to be readable, even in
small fragments.
Many people (myself included) think that typedefs for structure types
are useless in most cases. There's no good reason to define another
name (like, say, "WEIGHT") for something that already has a perfectly
good name (like "struct wnode"). There are even better reasons to
avoid typedefs for pointer types; a pointer to an object is very
different from the object itself, and hiding that distinction behind a
typedef can be positively dangerous.
So here's how I'd re-write your declaration above:
#define MAXRANK some_integer_constant_expression
struct wnode {
int weight[MAXRANK+1];
struct wnode *next;
};
Any code using this type would then simply refer to it as "struct wnode";
if you want a pointer, refer to it as "struct wnode *".
Now install is a funcition that returns a pointer to the frist vector
in the list, Can anyone give the code to define this funcition.?
With the information you've given us, probably not. Show us some real
code. Don't try to paraphrase it; copy-and-paste the exact code that
you fed to the compiler. Otherwise, there's no way we can guess which
errors are in your actual code, and which you introduced by re-typing
it (such as your double declaration of WEIGHTPTR).
Try implementing the function yourself. If you run into trouble, show
us what you have and explain what it's supposed to do, and how that
differs from what it actually does. We'll be glad to help if we can,
but we aren't going to write it for you.