Hi eVeryone,
Please help me on below code. I don't know what's the erorr mean.
Error Message
*test.c: In function ‘main’:
test.c:12:2: warning: passing argument 2 of ‘tokenise’ from incompatible pointer type [enabled by default]
test.c:5:6: note: expected ‘char **’ but argument is of type ‘char * (*)[100]’
test.c: In function ‘tokenise’:
test.c:22:6: warning: assignment makes pointer from integer without a cast [enabled by default]
test.c:28:7: warning: assignment makes pointer from integer without a cast [enabled by default]
*
#include <stdio.h>
#define MAX_NUM_TOKENS 100
void tokenise(char inputLine[], char * tokens[]);
void main()
{
char *result;
char inputLine[] = "Testing program Testing program";
char *tokens[MAX_NUM_TOKENS];
tokenise(inputLine, &tokens);
printf("token: %s", tokens);
}
void tokenise(char inputLine[], char * tokens[])
{
int i = 0;
char *pch;
pch =strtok(inputLine, " ");
while(pch != NULL)
{
tokens[i] = pch;
i++;
pch = strtok(NULL, " ");
}
}
I wanted to pass the inputLine from MAIN to Tokenise then in Tokenise split the inputLine with the delimiter space. After spliting then put it back to the tokens[]. I have used by reference for the tokens. But i am facing some issue with the by reference that i could not really understand. Can some one please guide me and let me understand what's the problem with the code?
Thank you for your time and effort.