0
votes

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

1
not a valid solution to what ?Zitrax
When I try int x=10; LLIST *mylist[x] = {NULL}; I get an error when I compile the solution given compiles but doesnt work.MRP

1 Answers

0
votes

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));