Stupid mistakes in C programming

These are some stupid mistakes I made programming C.

strlen ("\0");

I used strlen ("\0") in malloc as a substitute for 1. This is stupid because it gives a value of zero. The correct way to do this is to write sizeof ((char) '\0').

Ask and answer questions on C in the new C forum

Copyright © Ben Bullock 2009-2012. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (ben.bullock@lemoda.net) / Privacy / Disclaimer