Yes, it can be solved by declaring it as an extern
variable, but it needs to be global in source1.c too. Local variables cannot be accessed from outside their scopes, at least not by name.
So, in source1.c:
char day[7];
void function1(void)
{
day[0] = ...;
/* and so on */
}
then in source2.c:
extern char day[7];
void function2(void)
{
printf("oh, source1 has set day[0] to %c\n", day[0]);
}
of course, you must make sure that function1()
from source1.c runs before function2()
from source2.c, in order to initialize the array.
You could have a separate main.c that does:
int main(void)
{
function1();
function2();
return 0;
}
Then compile them all together, using something like this (assuming gcc in a Unix-type environment):
$ gcc -o myprogram main.c source1.c source2.c