When an error is detected with malloc(), calloc()and realloc()(that is, they return a NULL pointer), is set errno. Then you can use the standard function perror()to print the error without having to do your own formatting. Please note that it will automatically print on stderr, no need to worry about it.
, , . main(), return EXIT_FAILURE; exit(EXIT_FAILURE);, . .
, , .
, , realloc() NULL, free d .