Hi guys,
I'm new to this forum.
I'm trying to understand the way "delete" and "new" works.
I wrote a simple program that convert CAPS letter to regular ones.
The main calls a function that ues the "new" command and I need to delete that new pointer after the function returns the value.
I don't why but the delete command causes a "Heap corruption" crash.
Can you please help me out ?
Thank you very much guys...
1. main must return int (otherwise most people won't be able to compile your program)
2. replace resultStr = newchar[stringSize]; with resultStr = newchar[stringSize+1]; Your strcpy wrote past the end of the memory block allocated by new[] and thus corrupted the heap.
3. don't use arrays of char to handle strings