Use of "EXTERN" Keyword in header file while its definition in source file
<p>I am new to C programming and was attempting to write a code in which values of variables x and y are taken from the user in the main function of File1.c. All other functions in the file use the value of these variables. I have used 'extern' keyword to declare it in Header file Header.h and this header file also makes use of the values of x and y entered by the user. Another File2.c also makes use of these variables. Both File1.c and File2.c include Header.h </p>

<p>I have defined variables x and y as global variables in File1.c but I am constantly getting segmentation faults. How should I proceed? </p>

<p>EDIT:
Here is the code:</p>

<pre><code>#include&lt;stdio.h&gt;
#include&lt;Header.h&gt;
 int x,y;
 int main() 
{
  uint16_t *Buffer_1 = (uint16_t *)malloc(sizeof(uint16_t) *x*y*256);
  uint16_t *slice = (uint16_t *)malloc(sizeof(uint16_t)*x*y);
  printf("Enter value of x: );
  scanf("%d",&amp;x);
  printf("Enter value of y: );
  scanf("%d",&amp;y);
  memcpy(slice,Buffer_1,x*y*sizeof(uint16_t));
 }
</code></pre>

<p>I get segmentation fault at memcpy. I have declared variables x,y in Header.h as follows:</p>

<pre><code>#include &lt;stdio.h&gt;
extern int x;
extern int y;
</code></pre>