I have an array containing arrays of chars, these are tokens from a tokenised string!!! so basically, looks something like....
- string one -
- string two -
- string three -
and so on....
Basically, I want to access this array of tokens in another function in my program!
I know this is not the best description! ...But, it shows the fundamental concept of what goes on! ...I have a pointer to an array of pointers that point to individual char arrays (the tokens), I want to pass this pointer to the calling funciton so i can use the tokens in the other funciton!!!!!!Code:char ** stringTokenizer(char * theData, char * theDelims){ static char *Token[5]; /* ARRAY TO STORE POINTERS TO TOKENS */ /* FUNCTION TOKENISES INPUT STRING HERE AND RETURNS THE TOKENS */ return tokens; } main () { char ** tokens; /* POINTER TO THE TOKENS */ char mystring = "This is a test string"; /* TOKENISE mystring DATA */ tokens = stringTokenizer(mystring, " \r \n : ; #"); /* T0 ACCESS THE TOKENS: tokens[0] = "This" tokens[1] = "is" tokens[2] = "a" tokens[3] = "test" tokens[4] = "string" */ if (strcasecmp(tokens[0], "this") == 0) { /* COMPARE FIRST TOKEN */ printf("found \"this\" token\n"); } anotherFunction(tokens); /* CALL ANOTHER FUNCTION AND PASS THE TOKENS ARRAY TO IT! */ } anotherFunction(inToks) { }
I hope this makes some sense!!!!!!
I want to be able to access the tokens (in the other function) by doing something similar to ;
tokens[x] (will retrieve the token in position x)
...In the same way as i can in the main function!!!! ...Basically, I want to compare the tokens and find out what tokens contain certain data!!! (it is for university coursework, for a client server application, so packet data is the individual tokens and needs to be processed in different functions!!!!)
Thanx for any help!!!!!!!! I hope it is understandable what i am trying to do!!!!!!!!



LinkBack URL
About LinkBacks


