c - Setting a specific element of a char** array to NULL -
i attempting set last element in second char **
array null
after encounter specific char in first array.
int test(char ** args){ char ** chmd1; for(int = 0; args[i] != null; ++i){ if(!strncmp(args[i], "<", 1)){ chmd1[i] = null; break; } chmd1[i] = args[i]; } for(int = 0; chmd1[i] != null; ++i){ printf("%s", chmd1[i]); } return 0; }
this code segfaults second loop goes on more iterations past null
should be.
i want able able manipulating pointers , not using mallocs, i'm stuck.
this code segfaults second loop goes on more iterations past the null should be.
you have not allocated memory chmd1
, yet using points valid memory.
i want able able manipulating pointers , not using mallocs, i'm stuck.
you can't that. have use malloc
(or 1 of other functions malloc
group of functions: calloc
, realloc
) allocate memory chmd1
before can use it.