views:

28

answers:

1

So I have...

int x; LLIST *mylist[x]; x =10; bzero(mylist, sizeof(LLIST *)*x);

this does not seem to be a valid solution..

I did add the -std=c99 to my make file, just this alone did not work which is why emil suggested the above approach, because I had originally:

int x=10;

LLIST *mylist[x] = {NULL};

My make file looks like this:

CC=gcc CFLAGS=-Wall -g -std=c99

LIBS=-lreadline -lm OBJS=llist.o myprogram.o INCLUDES=llist.h

all: $(OBJS) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o myprogram

.c.o: $.h $(INCLUDES) $(CC) $(CFLAGS) -c $.c

clean: rm -f *.o myprogram

A: 

This code:

int x; 
LLIST *mylist[x];
x = 10;
bzero(mylist, sizeof(LLIST *)*y);

has two problems:

  1. You are using x line 2 before giving it a value on line 3.
  2. You are using variable y in line 4.

I recommend tow changes. First combine the definition and initialization of x into a single line. Second, use sizeof(VAR) and rather then recomputing the size based on the type:

int x = 10;
LLIST *mylist[x];
bzero(mylist, sizeof(mylist));
R Samuel Klatchko
sorry that was a typo suppose to be:bzero(mylist, sizeof(LLIST *)*x);
MRP
Okay.. I think i was able to get it to work... I will give it a try thanks for the help.
MRP