Multiple Double Linked Lists

L

Little

Hello everyone. I am trying to do the following program and am unable
to get the beginning portion to work correctly. The scanner works when
I print the statements without the double linked list portion but I
just need help with the beginning portion with the double linked lists.

Here is the information needed to understand the code:

Create 4 double linked lists as follows:

(a) A double linked list called NAMES which will contain all C like
identifiers of less than
256 characters long identified in the input file F. Each identifier
will be represented by
a triple (I, length, string) where I is used to identify the type of
the object as being an
identifier, length is an integer representing the length of the
identifier in characters, and
string is a string of characters representing the identifier itself.

(b) A double linked list called NUMBERS which will contain all C like
numbers of less than
256 characters long identified in the input file F. Each number will be
represented by a
triple (N, length, string) where N is used to identify the type of the
objects as being a
number, length is an integer representing the length of the number in
characters, and
string is the string of characters representing the number itself.

(c) A double linked list called SEPARATORS which will contain all C
language separators
and operators identified in the input file F. Each separator will be
represented by a triple
(X, length, string) where X is S for separators, O for operators, R for
symbols denoting
relations, L for new line and E for end of file. The length is an
integer representing the
length of the symbol and string is the string of characters
representing the symbol itself.

(d) A double linked list called UNKNOWN which will contain all symbols
you discovered in
the file F which could not be classi ed in the lists NAMES, NUMBERS,
SEPARATORS.
Each object in this list will be represented by a triple (Y, length,
string) where Y is used
to signify that an unknown symbol was discovered, length is an integer
representing the
length in characters of the unknown symbol, and string is the string of
characters that
make up the unknown symbol itself.

Thanks for the help

#include <stdio.h>
#include <stdlib.h>
#include "scan.h"
#define null 0

struct Names
{
struct Names *next;
struct Value *p_value;
struct Names *prev;
};

typedef struct Names DLList;
typedef struct Names header;
typedef struct header *headerpt;

struct Numbers
{
struct Numbers *next;
struct Value *p_value;
struct Numbers *prev;
};

typedef struct Numbers DLList;
typedef struct Numbers header;
typedef struct header *headerpt;

struct Separators
{
struct Separators *next;
struct Value *p_value;
struct Separators *prev;
};

typedef struct Separators DLList;
typedef struct Separators header;
typedef struct header *headerpt;

struct Uknown
{
struct Uknown *next;
struct Value *p_value;
struct Uknown *prev;
};

typedef struct Uknown DLList;
typedef struct Uknown header;
typedef struct header *headerpt;

struct Value
{
char Type;
int length;
char Value[256];
};

header *list(header *h, header *t)
{
h->prev=null;
h->next=t;
h->p_value=null;
t->prev=h;
t->next=null;
t->p_value=null;
return(h);
}

void append(header *l, DLList *obj)
{
DLList *q=l->next;
while(q->next != null)
q=q->next;
obj->prev=q->prev;
obj->next=q;
q->prev=obj;
q=obj->prev;
q->next=obj;
}

void printlist(header *pt)
{
DLList *q;
int i;
printf("\n->");
q=pt->next;
while(q->next != null)
{
i=q->p_value;
printf("%d->",i);
q=q->next;
}
printf("\n");
}

int main (int argc, char *argv[])
{
extern TKN get_token(FILE *);
TKN Token;
FILE *Input;
int Done = 0, k;
Input = fopen(argv[1], "r");
while (!Done)
{
Token = get_token( Input );
switch (Token.Code)
{
case 'I':
{
/* process identifier */
break;
}
case 'N':
{
/* process integer number */
break;
}
case 'F':
{
/* process real number */
break;
}
case 'W':
{
break;
}
case 'L':
{
break;
}
case 'U':
{
if (Token.String[0] == 'Z')
Done = 1;
else
break;
}
case 'O':
{
break;
}
}
} /* end while */
return 0;
}
 
K

Keith Thompson

Little said:
Hello everyone. I am trying to do the following program and am unable
to get the beginning portion to work correctly. The scanner works when
I print the statements without the double linked list portion but I
just need help with the beginning portion with the double linked lists.
[snip]

You posted this same question (or nearly so) in this newsgroup on
January 22, January 24, January 26, and now again on January 30. You
also posted the same question to comp.lang.c.moderated (it just showed
up today). You have gotten a number of responses, and you have
acknowledged none of them.

Asking the same question again and again will not get you better
answers. If the responses you've already gotten aren't helpful, post
another followup *in the same thread* asking for clarification. Don't
start a new thread each time.

You're wasting our time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top