PDA

View Full Version : strdup question



ToddAtWSU
23rd October 2007, 21:51
I am creating an array of char*'s from a vector structs I have. The structs all have a char* name and I want to copy these names into an array of names. I cannot always guarantee these names will not be "". I planned on using strdup to copy these char*s since I will never know what their length will be, but will strdup have a problem trying to copy an empty string? And then later when I free these (strdup uses malloc), will there be a problem? Thanks!

jacek
23rd October 2007, 23:08
There shouldn't be any problem, because an empty string is 1 byte long.