Typo and missing if
per @interjay.
Change
else (islower(message[i]));
to
// v
else if (islower(message[i]))
// or simply
else // Since `message[]` is an alpha, but not upper
With the error, when text was uppercase, both cipher[i] = (message[i] - 'A' ...
and cipher[i] = (message[i] - 'a' ...
occurred. Given cipher = message
, the cipher was applied twice.
@keshlam point about the missing buffer is a significant issue. But I wonder what type string
is. Is this some sort of C++ lite string? If it is a char *
, code could use cipher = strdup(message);
or
cipher = malloc(length + 1);
if (cipher === NULL) Handle_OutOfMemeory();
cipher[length] = '';
for ( int i = 0; i < length; i++)
...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…