Help in separating variables declared in the main function

Hi! I've a C program as shown below..
The line numbers and the statements of the program are separated by a space..

1 #include<stdio.h>
2 char a,b,c;
3 float x,y,z;
4 int main()
5 {
6 int d,e,f;
7 // further declarations
8 // further declarations
9 /* body*/
10 }
11 void fun1()
12 {
13 int g,h;
14 chat i,j;
15 /*function body*/
16 }
17 void fun1()
18 {
19 int k;
20 chat l,m;
21 /*function body*/
22 }

Is there anyway we can separate out the variables declared in main function from the variables declared outside the main function.. That is variables declared in other function definitions and in the global section..
I mean we need to store the variables declared in the main() in one file and the rest of the variables(including the global declarations) in another file..
Note the line numbers may not be in order..

Any idea??
Thanks in advance.. :slight_smile:

If i have understood your question correctly you can try this..
<code>
#include<stdio.h>
//char a,b,c;
//float x,y,z;
#include "globalvariables.h"
int main()
{
// int d,e,f;
#include "mainvariables.h"
// further declarations
// further declarations
/* body*/
}
void fun1()
{
//int g,h;
//chat i,j;
#include "fun1variables.h"
/function body/
}
void fun1()
{
int k;
chat l,m;
/function body/
}

</code>

Keep Global variables in globalvariables.h file and main variables in mainvariables.h, fun1variables.h file has fun1 variables.

sorry if your question is different..

For the best practise have #define variable in each header file, check that variable is defined in the including file. Otherwise you might have duplicate variable declaration.