Programming help please, character array problems

teiresias

Senior member
Oct 16, 1999
287
0
0
Can someone please explain to me why the code below crashed before the end of execution:


#include <string.h>
#include <stdio.h>

void main()
{
char *DestinationString;
char *SourceString;
int k;

DestinationString = new char[];
SourceString = new char[];

if (DestinationString == NULL || SourceString == NULL)
printf("Error allocating memory!" );
else
{
strset(DestinationString, NULL);
strset(SourceString, NULL);

for ( k=0; k < 10; k++)
SourceString[k] = 'J';

for ( k=0; k < 10; k++)
DestinationString[k] = 'Z';

strcpy(DestinationString, SourceString);

strlwr(SourceString);

printf("SourceString: %s", SourceString);

printf("\n" );
printf("DestinationString: %s", DestinationString);

delete []DestinationString;
delete []SourceString;
}
}



It will get to the delete instructions and give me a debug error that says:


Quote:
--------------------------------------------------------------------------------
DAMAGE: after Normal block (#20) at 0x00780EC0
--------------------------------------------------------------------------------



However, if I change the arrays to integer arrays the program works fine (granted with some changes to the assignements so I'm actually assigning integers), however, using characters it always crashes. Any thoughts? Thanks everybody.