extern int grid[];
Let's suppose you had some code like this:
int grid[] = { 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
1 , 2 , 3 , 2 , 3 , 2 , 3 , 1 ,
1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ,
1 , 0 , 1 , 0 , 1 , 0 , 1 , 1 ,
1 , 0 , 1 , 0 , 0 , 0 , 0 , 1 ,
1 , 0 , 0 , 0 , 0 , 0 , 1 , 1 ,
1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 };
int arr_sum(int* arr, int len)
{
int sum = 0;
for (int i = 0; i < len; i++) {
sum += arr[i];
}
return sum;
}
int main(int argc, char** argv)
{
printf("%d\n", arr_sum(grid, sizeof(grid)/sizeof(int) ));
return 0;
}
If you wanted to separate this out into two different files, say, you could have the following, for example:
in grid.c:
int grid[] = { 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
1 , 2 , 3 , 2 , 3 , 2 , 3 , 1 ,
1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ,
1 , 0 , 1 , 0 , 1 , 0 , 1 , 1 ,
1 , 0 , 1 , 0 , 0 , 0 , 0 , 1 ,
1 , 0 , 0 , 0 , 0 , 0 , 1 , 1 ,
1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 };
In main.c:
extern grid[];
int arr_sum(int* arr, int len)
{
int sum = 0;
for (int i = 0; i < len; i++) {
sum += arr[i];
}
return sum;
}
int main(int argc, char** argv)
{
printf("%d\n", arr_sum(grid, sizeof(grid)/sizeof(int) ));
return 0;
}