423,850 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,850 IT Pros & Developers. It's quick & easy.

Multiple Double Linked Lists

P: n/a
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;
}

Jan 30 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Little" <co************@yahoo.com> writes:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Jan 30 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.