title: Can we declare, define & assign values to a variable and use those variables in another file?
body: <p>I am a beginner to C programming and I'm trying out different methods and experimenting with small programs. </p>
  
  <p>I have four files. two header files and two source files. I want to:</p>
  
  <ol>
  <li>Declare a variable (Actually two variables and a char) and a
  function (from the second source file) in one header  file.</li>
  <li>Define these variables and assign values to them in a second header
  file(variables from point 1).</li>
  <li>Write a function including these two header files and using the
  values from these files(point 2) in one source file (without a main-
  just a function definition using the variables).</li>
  <li>Have a main source file that invokes the function from the second
  source file (from point 3.)</li>
  </ol>
  
  <p>How do I come about this? I have included both header files in both the .c files. But when I try to compile and link it (using GCC in Linux) I get a
   <code>multiple definition ... first defined here</code> error for all the variables. </p>
  
  <p>I have looked at these answers <a href="https://stackoverflow.com/questions/672734/how-to-prevent-multiple-definitions-in-c?rq=1">First</a> and <a href="https://stackoverflow.com/questions/2216765/variable-definition-in-header-files">Second</a>
  I didn't quite understand the answers in the <a href="https://stackoverflow.com/questions/2216765/variable-definition-in-header-files">Second</a> as I'm not able to figure out how to use header guards. 
  I am not able to figure out how to check all of the boxes (points one through 4).</p>
  
  <p>header1.h</p>
  
  <pre><code>extern int i,j; extern char c;
  void ad_d();
  </code></pre>
  
  <p>header2.h</p>
  
  <pre><code>int j=6;int i=7;
  char c='x';
  </code></pre>
  
  <p>fnfile.c</p>
  
  <pre><code>#include "header1.h"
  #include "header2.h"
  #include&lt;stdio.h&gt;
  
  void ad_d()
  {
  
      i+=j;
  
      printf("\n %d \t %c \n", i,c);
  }
  </code></pre>
  
  <p>filemain.c</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include "header1.h"
  #include "header2.h"
  
  
  
  void main()
  {
  
      ad_d();
  }
  </code></pre>