C
Coolm@x
Hi all,
I want to write my own explode (split) function and I need copy string
char by char. I learn pointers and my knowledge about them isn't so big.
int func(char delimiter, char *expression, char **values) {
(...)
//why I can't write this:
memcpy(values[tmplen-1],expression,1);
//only this weird expression work:
memcpy((*(values+i))+(tmplen-1),&expression[n],1);
}
int main() {
char **val;
val = malloc(sizeof(*val));
func(';', "foo;bar", val);
return EXIT_SUCCESS;
}
I know if I declare pointer to char variable:
char *word;
word = malloc(5*(sizeof(*word)));
'[]' - works as '*' operator (If i read good tutorials )
word[0] // same as *word
....
word[4] // *(word+4)
so why first way to use of 2d array of chars doesn't work with memcpy,
strcpy (and I think other similar functions)? I would appreciate any help.
--
Best regards,
- Mateusz Pa³osz
[ e-mail: matp dot sa a-t gmail dot com ]
[ JID: (e-mail address removed) ]
[ Pomó¿ ulepszyæ usenet: http://twovoyagers.com/improve-usenet.org/ ]
I want to write my own explode (split) function and I need copy string
char by char. I learn pointers and my knowledge about them isn't so big.
int func(char delimiter, char *expression, char **values) {
(...)
//why I can't write this:
memcpy(values[tmplen-1],expression,1);
//only this weird expression work:
memcpy((*(values+i))+(tmplen-1),&expression[n],1);
}
int main() {
char **val;
val = malloc(sizeof(*val));
func(';', "foo;bar", val);
return EXIT_SUCCESS;
}
I know if I declare pointer to char variable:
char *word;
word = malloc(5*(sizeof(*word)));
'[]' - works as '*' operator (If i read good tutorials )
word[0] // same as *word
....
word[4] // *(word+4)
so why first way to use of 2d array of chars doesn't work with memcpy,
strcpy (and I think other similar functions)? I would appreciate any help.
--
Best regards,
- Mateusz Pa³osz
[ e-mail: matp dot sa a-t gmail dot com ]
[ JID: (e-mail address removed) ]
[ Pomó¿ ulepszyæ usenet: http://twovoyagers.com/improve-usenet.org/ ]