I am working in C trying to tokenize an array and then store the tokens to a global array of strings. The catch is that i am trying to do this with pointers so I do not have to refrence the index of the array of strings. I know how big the array is supposed to be which is why it is easy to do it with the index, HOWEVER; i am trying to do this with just pointers. I don’t know if this is possible so correct me here. Here is the code I have tried to implement but not been successful..
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *cPayload2[PARAMS];
void ReadIn2(char *input)
{
//Initialize the pointer to the
char *PayloadPtr;
//start the parse
char *token = strtok(input, "#");
//pointer to an array of strings(pointers to character arrays)
PayloadPtr = &cPayload2[0];
while(token != NULL)
{
This is the part in question, can i change the index of my global array with a clause like this. It seems I cannot print out the payload array with this.
*PayloadPtr = token;
//increment the index that the ptr refrences
PayloadPtr++;
//tokenize again
token = strtok(NULL, "#");
}
}
int main(void)
{
char input[] = "jsiUjd3762BNK==#KOIDKKkdkdwos==";
ReadIn2(input);
This printout is bunked for some reason
printf("%s\n",cPayload2[0]);
printf("%s\n",cPayload2[1]);
return 0;
}
Any tips would be greatly appriciated.
should be
apart from that, your code is alright.