Iam trying to compile a file of the following format by making a parser in bison

```
LOCATION house
NAME "House"
DESCRIPTION "You are standing\nin front of your house.\nPaths lead towards east and west."
east flag
west forest

LOCATION obelisk
NAME "Obelisk"
DESCRIPTION "A big obelisk is\nstanding before you. You can either go east or west or  south." 
south flag
east flag
west treasure

```

My parser has a function 

```
int find(char *id) {
int i;
for(i=0;i<nLoc;i++) {
if(strcmp(id,tmp_idList[i]) == 0){
    printf(tmp_idList[0]);
    printf(" i = %d returned",i);
return i;

    }
}

printf("Copying...");
strcpy(tmp_idList[nLoc],id);
printf("%d %s",nLoc,tmp_idList[nLoc]);
nLoc++;
printf(" nloc-1 = %d returned",nLoc-1);
return (nLoc-1);
}

```

It uses 

```
char tmp_idList[60][100];

```

Grammar is (relevant here )

```
locnSpec : tok_LOCN tok_IDENT nameSpec descrSpec exitList
            {int k = find($2);
             locList[k].name = strdup(tmp_name);
             locList[k].descr = strdup(tmp_descr);
             memcpy(locList[k].exits, 
                    tmp_exit,
                    4*sizeof(int));}

```

Now when i run this code, somehow 

```
 tmpidList[0] 

```

is getting populated with a junk value as shown below in the output

```
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\MY PC\Desktop\final>bison -d -o compile.c adv6.y

C:\Users\MY PC\Desktop\final>gcc -o compile compile.c lex.yy.c

C:\Users\MY PC\Desktop\final>compile<toy.al

 Copying...0 flag nloc-1 = 0 returned
 Copying...1 forest nloc-1 = 1 returned

Copying...2 house nloc-1 = 2 returned

 flag i = 0 returned // OK HERE
 flag i = 0 returned
 Copying...3 treasure nloc-1 = 3 returned

Copying...4 obelisk nloc-1 = 4 returned

Copying...5 marsh nloc-1 = 5 returned

 nd west. i = 4 returned // JUNK HERE
 Copying...6 flag nloc-1 = 6 returned
 nd west. i = 1 returned

nd west. i = 3 returned

 t. i = 4 returned
 t. i = 2 returned
 t. i = 4 returned

t. i = 6 returned

 t. i = 5 returned
 t. i = 2 returned
 t. i = 3 returned

t. i = 1 returned t. i = 2 returned

C:\Users\MY PC\Desktop\final>

```

As a cue when i tried allocating memory via malloc 

```
char* tmp_idList[20]

...

tmp_idList[nLoc] = malloc(strlen(id) +1 )

```

it worked fine till flag was there in tmp\_idList[0] but stopped working and there was a memory error in compile.exe.

does anyone has clue on what is happening? if you want more information , i can provide. i really need help for my college project.