Suppose i have a main.cpp file and a test.h file:
///////////////////////////////////////////
//main.cpp

#include <iostream.h>
#include <string.h>
void test();

char foo[200];
int main()
{
strcpy(foo, "testing");
test();
return 0;
}
//////////////////////////////////////////////////////////////
//test.h

void test()
{
cout << mir << endl;
}


WHY IS "mir" AN UNDECLARED IDENTIFIER

This has nothing to do with global variables, you simply never defined what mir is. (what data type)

And unless i'm mistaken, you forgot

#include "test.h"

Am sorry but i left many mistakes, undertand me, i typed this quickly without passing tru a compiler. I WAS RUNNING OUT OF TIME
HERE IS THE CORRECTED CODE:

Suppose i have a main.cpp file and a test.h file:

///////////////////////////////////////////
//main.cpp

#include <iostream.h>
#include <string.h>
#include "test.h"

void test();

char mir[200];
int main()
{
strcpy(mir, "testing");
test();
return 0;
}
//////////////////////////////////////////////////////////////
//test.h

void test()
{
cout << mir << endl;
}

<< moderator edit: added [code][/code] tags >>

You are still not declaring mir in the test.h file. When you are using a variable in C and it is declared in a different file you have to declare it again using the "extern" keyword to let the compiler know that the variable is declared else where, so try...

main.c (using C code instead of C++)

#include "test.h"

char mir[200]="testing";

int main()
{
      test();
      return 0;
}

test.h

void test()
{
     extern char mir[200];
     printf("%s\n, mir);
}

My compiler was complaining about my iostream.h file so i just used the printf instead and omitted the need for string.h but initializing the char array when i declared it.

Maybe something like: extern char mir[200]; in test.h can solve your problem ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.