I have a function tokenize and I want to modify a char pointer array through the function. But I don't get the result after many tries. Could someone help me?
Below is the code:
void **tokenize(char **argv, char *line, int *numTokens, char *delimiter)
{
int argc = 0;
char *token = strtok(line, delimiter);
while (token != NULL)
{
argv[argc++] = token;
token = strtok(NULL, delimiter);
}
argv[argc++] = NULL;
*numTokens = argc - 1;
}
void process_cmd(char *cmdline){
char *temp[20];
int *num2;
tokenize(temp, cmdline, num2, "|");
printf("%s\n", temp[0]);
printf("%s\n", temp[1]);
printf("%d\n", *num2);
}
num2pointing? Perhaps you should take more time to study how emulating pass by reference in C really works, and how to use the address-of operator&.