dynamic memory allocation. If I want to use calloc, I use and want to delete it from your machine, it is your decision.
1 - Tell me what is the difference between this :
char **f = (char **)calloc(1, sizeof(char *));
and this:
char **f = (char **)malloc(1 * sizeof(char *));
2 - You do not read what I wrote. He might want to be sure that all allocated memory starts with zero. Can you guarentee with that malloc? How do you know his requirements? Without req, you cannot say no reason for it.
This is a simple split function
wait a second, i'm sorry, in first look i did not see that realloc in code so one problem does not exist anymore. so the main problem is just allocating as much as strlen and strcpy() on it which is writing + 1 outside of buffer for null terminator. also these mem allocation functions requires casting to needed type. but still 0- there is no standard because c devs want control. if you want 0 it all for no reason it's your choice, i won't waste resources for your product. 1- that's not the point. calloc is just zeroing one pointer's value in that case. the main zeroing problem starts in loop on zeroing so many unnecessary bytes also dynamically so with many bytes its a continuely hiccup until end. anyway even with few bytes, any issue more than 0 if remain on purpose shows programmer's irresponsibility which is dangerous in unseen parts of the project. if somebody want be sure that all buffers start with 0 (which is not necessary in context of this code) so will zero one first byte of it not all of it. his requirement is pretty clear in this code.
Обсуждают сегодня