I'm using a for loop to assign chars to each element of an array one at a time. The array has been assigned a size and the for loop runs the same number of iterations as the array size, but I find that as soon as I assign a value to the 8th element of the array (cypstring[7]), the size of the array increases to 14, even though I may have given it a size of say 10, assigning random characters to the last 4 elements.
int ciphertext(char cypherchk[], string plainstring)
{
int plainlength = strlen(plainstring);
char cypstring[plainlength];
for (int n = 0; n < plainlength; n++)
{
int asc = toupper(plainstring[n]) - 65;
if (isupper(plainstring[n]) != 0)
{
cypstring[n] = toupper(cypherchk[asc]);
}
else if (islower(plainstring[n]) != 0)
{
cypstring[n] = tolower(cypherchk[asc]);
}
else
{
cypstring[n] = plainstring[n];
}
}
printf("ciphertext: %s\n", cypstring);
return 0;
}
Any ideas about what is going on?