3 ms·
The code in K&R looks correct to me as written. The copy function is only called on char arrays obtained from getline which properly null terminates the array.
by slkpg 12y ago
The code in K&R looks correct to me as written. The copy function is only called on char arrays obtained from getline which properly null terminates the array. As pointed out, C style "strings" do not work if the null terminator is not present. If underlying assumptions are not valid in any context, nothing can be assumed to work. The text about malloc vs stack is both wrong and not relevant.
- zedshaw 12y agoThank you for proving my point. It is right as long as the tower of babel it's used in never collapses. The problem is, as with every book with code ever in the universe, beginners will copy that code out and use it somewhere else and then the function is wrong. And, you literally just repeated every single argument I demolish in the chapter, which means you didn't read it.