I've got this problem:
I have two arrays.
The first is just a char array that contains for example this:
Code:
!cmd
!cmd2
!cmd3 paramater
!cmd4
And I need to get it into an array of a struct. Struct is as follows:
Code:
typedef struct {
char *cmd;
char *para;
} g_acl_Commands_t;
If I would fill it from the code, I would do this:
Code:
static g_acl_Commands_t aclCommands[] =
{
{ "!cmd", '' },
{ "!cmd2", '' },
{ "!cmd3", "testcode" },
{ "!cmd4", '' },
};
But it needs to be done in runtime, and the first array can change.
So I determine the first position of the !, and then the first coming newline, string terminator or space, then I have a starting point and an ending point which I need to copy, but now the problem is, how do you do that? :P
I tried with a for loop:
Code:
b = 0;
for (a = startpoint; a < endpoint; a++)
{
temparray[b] = firstarray[a]
b++;
}
then I would copy the temparray to the array of that struct, and then repeat the whole thing every time I have found new points, until there are no more, and then I should have an array of that struct filled with the right data, but it doesn't work, so how do I do that?