Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_CMD_LINE 500
void tokenize(char *cmd_ln, char *fun_tknzd[], int *argument_cnt);
int main(void)
{
char cmd_ln[MAX_CMD_LINE], *str_tknzd[MAX_CMD_LINE];
int argument_cnt = 0;
//I think my problem is here
tokenize(cmd_ln, &str_tknzd[MAX_CMD_LINE], &argument_cnt);
/* I am getting a null here i am not sure why, but i think it has something to do with how I am passing the array to the function. It does however print fine inside of the function */
printf("Out of function %s\n", str_tknzd[0]);
return 0;
}
void tokenize(char *cmd_ln, char *fun_tknzd[], int *argument_cnt)
{
int i = 0;
fun_tknzd[0] = strtok (cmd_ln," ");
//Just testing to see if the strtok is working correctly
printf("Test: %s\n", fun_tknzd[0]);
argument_cnt++;
printf("Argument count: %d\n", *argument_cnt);
while (fun_tknzd[i] != NULL){
/*Just testing to see if the strtok is working correctly and I enter the loop*/
printf("Entered Loop: %d\n", i);
printf("Got %s\n", fun_tknzd[i]);
i++;
fun_tknzd[i] = strtok (NULL, " ");
argument_cnt++;
}
I am trying to pass the value of fun_tknzd to str_tknzd
Thanks in advance for the help