M
merrittr
I define 2 variables (that I need to be globally accesible in all
files in this program)
in the file stack.c (functions push and pop):
//stack.c defnition if params
int iSp=0;
char *iItem[100];
But I also need to use iItem in a function stored in
strings.c (print which prints the stack)
void print(char *p)
{
printf("p\n");
int top=iSp-1,count;
for (count=0; count <= top; count++)
{
printf("print:%s\n",iItem[count]);
}
}
where/how do I declare iSp and iItem so all functions can access it?
See the command line
I use below to compile and the resulting errors.
$ gcc calculator.c stack.c strings.c math.c -o calculator.exe
..
calculator.c: In function `main':
calculator.c:70: error: `iItem' undeclared (first use in this
function)
calculator.c:70: error: (Each undeclared identifier is reported only
once
calculator.c:70: error: for each function it appears in.)
strings.c: In function `print':
strings.c:14: error: `iSp' undeclared (first use in this function)
strings.c:14: error: (Each undeclared identifier is reported only once
strings.c:14: error: for each function it appears in.)
strings.c:17: error: `iItem' undeclared (first use in this function)
strings.c: In function `printReverse':
strings.c:24: error: `iSp' undeclared (first use in this function)
strings.c:27: error: `iItem' undeclared (first use in this function)
files in this program)
in the file stack.c (functions push and pop):
//stack.c defnition if params
int iSp=0;
char *iItem[100];
But I also need to use iItem in a function stored in
strings.c (print which prints the stack)
void print(char *p)
{
printf("p\n");
int top=iSp-1,count;
for (count=0; count <= top; count++)
{
printf("print:%s\n",iItem[count]);
}
}
where/how do I declare iSp and iItem so all functions can access it?
See the command line
I use below to compile and the resulting errors.
$ gcc calculator.c stack.c strings.c math.c -o calculator.exe
..
calculator.c: In function `main':
calculator.c:70: error: `iItem' undeclared (first use in this
function)
calculator.c:70: error: (Each undeclared identifier is reported only
once
calculator.c:70: error: for each function it appears in.)
strings.c: In function `print':
strings.c:14: error: `iSp' undeclared (first use in this function)
strings.c:14: error: (Each undeclared identifier is reported only once
strings.c:14: error: for each function it appears in.)
strings.c:17: error: `iItem' undeclared (first use in this function)
strings.c: In function `printReverse':
strings.c:24: error: `iSp' undeclared (first use in this function)
strings.c:27: error: `iItem' undeclared (first use in this function)