Re: Double Linked List Code



"Little" <cookiecandyred@xxxxxxxxx> writes:
> Could someone help me figure out how to put my project together. I
> can't get my mind wrapped around the creation of the 4 double Linked
> Lists. Thank your for your insight.

I'm going to comment on some specific errors in your program, not on
how to solve your problem. Others might jump in and help with the
problem itself, or I might do so later.

[...]
> Here are the three files that i have created:
> main.c
>
> #include <stdio.h>
> #include <stdlib.h>
> #include scan.h

This is not a legal form for an include directive. You want
#include "scan.h"
Did your compiler accept this?

> #define null 0

Don't do this; just use the predefined macro NULL.

> #define true 1
> #define false 0

You never even use these.

> struct NAMES{
> char Name[256];
> struct NAMES *Next;
> struct NAMES *Prev;
> };
>
> typedef struct NAMES NAMES;
> typedef struct NAMES header;
> typdef header *headpt;

This is a typo; it's spelled "typdef". I'm not just being picky.
This is obviously not the code you actually tried to compile; if it
were, you would have corrected this error.

If you're going to post C code, post the *exact* code that you
compiled. Don't try to recompile it; copy-and-paste, insert the file,
or whatever. We're not going to waste our time guessing which errors
are in the original source files, and which ones you introduced by
re-typing it.

The typedefs are unnecessary; you can just use "struct NAMES"
directly. Having two names for the same structure is confusing.
Having another name for a pointer to that structure is equally
confusing. By using typedefs, you're hiding the fact that your types
are structures or pointers, making your code more difficult to follow.

> header *list(h,t)
> header *h, *t;
> {

This is an old-style function declaration. You're unlikely to run
into a compiler that doesn't support modern prototypes. With a
correct prototype, this would be:

header *list(header *h, header *t) { ... }

> h->Prev=null;
> h->Next=t;
> h->Name=null;
> t->Prev=h;
> t->Next=null;
> t->Name=null;
> return(h);
> }
>
> append (l,obj)
> header *l;
> NAME *obj;
> {

Another old-style declaration, and implicit int to boot. Since
append() doesn't return a value, it should be declared to return void:

void append(header *l, NAME *obj) { ... }

[snip]

> main (argc, argv)
> int argc;
> char *argv[];
> {

Another old-style declaration. Note that main() returns int, so this
should be:

int main(int argc, char *argv[])
{
...
return 0;
}

(Falling off the end of main() without returning a value is allowed in
C99, but it's still a bad idea.)

[snip]

> scan.h
>
> #include <stdio.h>
> #define MAX_STRING 32
> typedef struct t_node
> {
> char Code;
> char String[ MAX_STRING ];
> } TKN, *TKN_PTR;

You don't use anything from stdio.h in scan.h; why the include
directive?

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages