I have problem. I have stroke: "/hello/world" I need to copy word 'hello' to another string;
I have this code:
void copy(char *command) {// copy
char *word = NULL;
int size = 1;
if (*command == '/') {
command++;
while (*command != '/') {
word = (char*)realloc(word, size * sizeof(char));
*word = *command;
size++;
word++;
command++;
}
printf("%s", word);
free(word);
}
but I get this error: Segmentation fault (core dumped)
What I do wrong?