Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
hxchen
· 8y ago · 0 comments
Or use calloc. It does the same thing as malloc, but init memory to zero automatically.
Comments
[–]
tinus_hn
8y ago
If you’re going to allocate the memory you might as well just use the library functions that allocate exactly the space you need and copy the string into it. These tricks are for when you use the stack as an ‘optimization’.