Returning array of strings from a function and assigning it to variable later prevents function from working : I have a small question. I have this function, returning a char**. (I'm not sure its working but I think it is).

    char** parse_cmdline(char* cmdline) {
    	char ** arr = malloc(10 * sizeof(char*));
    	for (int i =0 ; i < 10; ++i)
        	arr[i] = malloc(30 * sizeof(char));
        char * token = strtok(cmdline, " ");
        int i = 0;
        while(token != NULL) {
        	if(i > 9) arr = realloc(arr, (i+10)*sizeof(char*) );
        	arr[i] = token;
        	token = strtok(NULL, " ");
        	i++;
        }
        printf("flag1");
        return arr;
    }

then i want to assign the return value to a variable in my main function

    if(fgets(cmd, sizeof cmd, stdin) == NULL) break;
    char ** commands = parse_cmdline(cmd);
    printf("%s", commands[0]);

and literally nothing happens. Not even the printf("flag1"); prints. But if I remove the `char ** commands` and put the `printf("%s", commands[0]);` in the parse_cmdline function, everything works, except im not assigning the return. Why and how to fix it?