Bill Cunningham said:
Ok I didn't put the includes and the struct in a header file to share
amongst .c files. I made changes and there's still a problem with malloc. I
haven't usesd malloc on my own so I don't know much about it. Only that it
returns void * and free() is needed after using it.
There's more to know about malloc() than that. And you can very
easily learn what you need to know by reading the documentation, which
will tell you, among other things, what argument it expects.
[...]
struct node { [...]
};
struct node *newNode(int data)
{
struct node *node = malloc(*node);
[...]
Once piece of advice: don't use the same identifier for two
different things. Here you're using it both for the struct tag
and for a pointer object. This is legal, but it makes it more
difficult to talk, or even think, about your code.
Your variable "node" is a pointer, not a node, so "node" is a bad
name for it.
As for your mis-use of malloc, I'll repeat
some advice I gave you over a year ago; see
http://groups.google.com/group/comp.lang.c/msg/6da991ad26d30ed9,
Message-ID <
[email protected]>, for the full article.
Every time you want to use a function from the standard C library,
whether it's fopen, fclose, printf, fprintf, isalpha, or anything
else, LOOK IT UP FIRST. Have the documentation for the function in
front of you, and read and *understand*:
what the function does;
the meanings and types of its arguments;
the meaning and type of its return value;
and the header in which it's declared,
before you even consider typing the first letter of the function's
name.
Don't use a function without knowing where it's declared. Don't use a
function without understanding what it does. Don't compare a
function's return value to NULL until and unless you *know* that it
returns a pointer, and what a NULL result means.
I have to look this stuff up myself. I honestly couldn't tell you
with certainty off the top of my head the order of the parameters for
fwrite(). (I just now checked the man page, and found that I had
mentally reversed the second and third parameters.)
If you can learn that lesson (and *retain* it), you'll have made some
actual progress.