• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Programming help please, character array problems

teiresias

Senior member
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.
 
Back
Top