Question: There is a header file named 'AAA.h'. In this header file we have define a structure called `lrd`, which looks like:

```
struct lrd
{   
int     tc;
char    ptc[5];
char    stc[5];
char    ath[5];
int     vc;
};
struct lrd lr;

```

This header file 'AAA.h' is included in two different files name 'BBB.c' and 'CCC.c'. We have assigned the values for structure variable `lr` in the 'BBB.c' file as following: 

```
lr.tc=tc;
memcpy(lr.ptc,ptc,sizeof(ptc));
memcpy(lr.stc,stc,sizeof(stc));
memcpy(lr.ath,ath,sizeof(ath));
lr.vc=vc;

```

Above source variables take the value from database. And we use structure variable `lr` in the 'CCC.c' file. We are using structure lrd variable as follows:

```
char *ptc()
{
    sprintf(str, "lr.ptc(%s)", lr.ptc);
    trace(str);
    return lr.ptc;
}
char *stc()
{
    sprintf(str, "lr.stc(%s)", lr.stc);
    trace(str);
    return lr.stc;
}

```

**Variable stc gives the wrong value in the 'CCC.c' file.**
Please help me to figure it out.

Answer: 
See what `benjarobin` says. I am just showing you a small footprint

AAA.h

```
#ifndef _AAA_H
struct abc
{
 int x;
 char *y;
 char *Z;
};

extern struct abc p;

extern void assign(void);
extern void display (void);
#endif

```

CCC.c

```
#include <stdio.h>
#include "AAA.h"

struct abc p; // Deceleration of p
void assign ()
{
    p.x=20;
    p.y="abcd";
    p.Z="xyz0";

    return;
}

```

BBB.c

```
#include <stdio.h>
#include "AAA.h"

void display (void)
{
    printf("x = %d, y =%s, z=%s",p.x,p.y,p.Z);

}

```

DDD.c contains the `main function`.

```
#include <stdio.h>
#include "AAA.h"
void main ()
{
    printf("\n\nAssigning Values\n\n");
    assign ();

    printf("\n\nIN BBB.c\n\n");
    display ();

    printf("\n\nIN MAIN\n\n");
    printf("x = %d, y =%s, z=%s",p.x,p.y,p.Z);

}

```

output is 

```
Assigning Values

IN BBB.c

x = 20, y =abcd, z=xyz0

IN MAIN

x = 20, y =abcd, z=xyz0

```
External variable should be avoid, but if you still want to use a global variable, you shall do these :

* Declare the variable in a .c file 

struct lrd lr;
* Add the external definition in the .h (AAA.h)

external struct lrd lr;