C
Chris Johnson
I've got a program that has two functions, and both need to access an
array. However, the size of the array is not even defined until I'm
partially through the main() function. Here's a quick demonstration of
what I need:
#include <stdio.h>
#include <stdlib.h>
void fubar(int,int);
// This is the array I want to make available to both functions
int equation[count];
int main()
{
int y, count = 0;
while(scanf("%d",&y) != EOF)
count++;
fubar(y,count);
printf("%d\n",equation[0]);
}
void fubar(int y, int count)
{
int i;
for(i = 0; i < count; i++)
equation = y;
}
Effectively what I need is to be able to declare global variables within a
function. Is that possible? Or else is there a workaround?
array. However, the size of the array is not even defined until I'm
partially through the main() function. Here's a quick demonstration of
what I need:
#include <stdio.h>
#include <stdlib.h>
void fubar(int,int);
// This is the array I want to make available to both functions
int equation[count];
int main()
{
int y, count = 0;
while(scanf("%d",&y) != EOF)
count++;
fubar(y,count);
printf("%d\n",equation[0]);
}
void fubar(int y, int count)
{
int i;
for(i = 0; i < count; i++)
equation = y;
}
Effectively what I need is to be able to declare global variables within a
function. Is that possible? Or else is there a workaround?