How can I access a global pointer outside of a C function?
Posted
by patrick
on Stack Overflow
See other posts from Stack Overflow
or by patrick
Published on 2010-04-13T03:16:55Z
Indexed on
2010/04/13
3:23 UTC
Read the original article
Hit count: 249
Filed under:
c
I am trying to access the data of*tkn
within a different function in my program for example: putchar(*tkn);
It is a global variable but its not working correctly. Any ideas?
#define MAX 20
// globals
char *tkn;
char array[MAX];
...
void tokenize()
{
int i = 0, j = 0;
char *delim = " ";
tkn = strtok (str," "); // get token 1
if (tkn != NULL) {
printf("token1: ");
while ((*tkn != 0) && (tkn != NULL))
{
putchar(*tkn);
array[i] = *tkn;
*tkn++;
i++;
}
}
}
© Stack Overflow or respective owner