'Passing 2-d array by reference only passing first dimension back

So for an assignment I have to make a program that parses a string into words, making use of pass by reference to save the words to an array. I've almost completed the assignment, except when I try to print the results I find that only the first letter of each word got passed back out of the parsing function, and all other values of the array return null.

the array that's being passed is defined as char *tokenArray[MAXSTRING];

it is being passed to the array char **args[]. I know from various test prints that args is getting each complete word, it's just that for some reason only the first letter of each winds up in tokenArray.

the line where it's supposed to be being passed by reference is this:

tokenResult = makearg(strInput, &tokenArray);

corresponding to the function definition:

int makearg(char s[], char **args[])

If you need more information please dont hesititate to let me know. Im honestly just confused as hell right now and don't even really know what other sections of my code might be useful here.

EDIT: As requested, here's the complete program. Be warned, it's a lot messier than I'd like it to be for a variety of reasons

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>

int MAXSTRING = 255;

int makearg(char s[], char **args[]);

int main()
{
   char *tokenArray[MAXSTRING];
   char strInput[MAXSTRING];
   int tokenResult;
   int i = 0;
   int j = 0;

   printf("Input String to be Parsed: ");
   scanf("%[^\n]%*c", strInput);

   tokenResult = makearg(strInput, &tokenArray);

   printf("argc: %d\n", tokenResult);
   for (i = 0; i < tokenResult; i++)
   {
      printf("arg(%d): %s\n", i, (tokenArray[i][1])); //specifically tries to print the second character to make sure not just the 1st one got passed. right now this only returns null
   }
}

int makearg(char s[], char **args[])
{
   int numTokens = 0;
   int lastSpace = 0;
   int i = 0;
   int j = 0;
   int fakeI;
   char token[MAXSTRING];
   int subFromPos = 0;
   int firstToken = 1;

   *args = NULL;
   while ((s[i] != '\n') && (s[i] != '\0') && (s[i] != '\r'))
   {
      fakeI = i;
      if ((s[i + 1] == '\n') || (s[i + 1] == '\0'))
      {
         fakeI = i + 1;
      }

      token[i - lastSpace - subFromPos] = s[i];

      if ((s[fakeI] == ' ') || (s[fakeI] == '\n') || (s[fakeI] == '\0') || (s[fakeI] == '\r')) //checks for end of word
      {
         if (firstToken == 1)
         {
            token[fakeI - lastSpace] = '\0'; //appends \0 to end of word
            firstToken = 0;
         } else if (firstToken == 0){
            token[i - lastSpace] = '\0'; //appends \0 to end of word
         }
         *args = realloc(*args, (numTokens + 1)); //resizes the first dimension of args
         args[numTokens] = realloc(args[numTokens], (fakeI - lastSpace + 1)*(sizeof(char))); //resizes the second dimension of args
         printf("token: %s\n", token); //tests to make sure the token was isolated correctly
         while (token[j] != '\0')
         {
            args[numTokens][j] = token[j]; //writes token to args, character by character
            j++;
         }
         j = 0;
         printf("Saved Token: %c\n", args[numTokens][2]); //checks the third character of the word to make sure not just the 1st one got written
         numTokens++;
         lastSpace = fakeI;
         subFromPos = 1;
      }
      i++;
   }
   return numTokens;
}

EDIT 2: Here's the expected input and expected output for the program as it is currently written

Input String to be Parsed: hello my friend
 
argc: 3 //the total number of tokens in the array
arg(0): l //the third character of the 1st token
arg(1): (null) //third character of 2nd token ("my" only has 2 hence null) arg(2): i

I should also confess, I have been getting some compiler warnings, but I can't find a way to get rid of them that doesn't make the program crash due to a segmentation fault. They are as follows:

270a1.c: In function ‘main’: 270a1.c:20:4: warning: passing argument 2 of ‘makearg’ from incompatible pointer type [enabled by default] tokenResult = makearg(strInput, &tokenArray);

270a1.c:7:5: note: expected ‘char **’ but argument is of type ‘char * ()[(sizetype)(MAXSTRING)]’ int makearg(char s[], char **args[]);

270a1.c: In function ‘makearg’: 270a1.c:68:32: warning: assignment makes pointer from integer without a cast [enabled by default] args[numTokens][j] = token[j];



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source