Errors involving c style strings for a caesar cipher program

This is the code I have so far.


#include <iostream>
#include "proj1.h"
#include <cstring>
using namespace std;


int main()
{
Decipher (cipher[0], 'R');
return 0;
}

//Deciphers a message. cip[] is a char array containing a Cipher message
//as a null-term.

void Decipher(char Cip[], char key)
{
char intCip[MAXMSGLEN];
char intMessage[MAXMSGLEN];
char cipherFinal[MAXMSGLEN];
int intKey = (key - 'A');
for( int i = 0; i < strlen(Cip); i++)
{
if(Cip[i] >= 'A' && Cip[i] <= 'Z')
{
intCip[i] = key - Cip[i];
}
}
for( int i = 0; i < strlen(Cip); i++)
{
Cip[i] = (intCip[i] + (intKey % 26));
}
}

char SolveCipher(const char Cip[], char dec[])
{
return 0;
}



When I try to make the .exe I get this.

linux3[87]% make
g++ -Wall proj1.cpp -o program
proj1.cpp: In function ‘int main()’:
proj1.cpp:9: error: invalid conversion from ‘const char*’ to ‘char*’
proj1.cpp:9: error: initializing argument 1 of ‘void Decipher(char*, char)’
proj1.cpp: In function ‘void Decipher(char*, char)’:
proj1.cpp:20: warning: comparison between signed and unsigned integer expressions
proj1.cpp:27: warning: comparison between signed and unsigned integer expressions
proj1.cpp:17: warning: unused variable ‘intMessage’
proj1.cpp:18: warning: unused variable ‘cipherFinal’
make: *** [program] Error 1

the header file has MAXMSGLEN equal to 80.

it also contains "const char cipher[NUMMSGS][MAXMSGLEN]" and then defines all of the sentences. [0][1] would be the first letter of the first sentence.

the functions in the header are this.

/******************************************************
Decipher() - decipher a Caesar-enciphered mesage.
Preconditions: cip[] is char array of maximum
length MAXMSGLEN containing a cipher message as
a null-terminated C-string. key is a capital
letter (A-Z) and is the Caesar cipher key.
Postconditions: cip[] is overwritten with the
deciphered message.
******************************************************/

void Decipher(char cip[], char key);

and this

/******************************************************
SolveCipher() - decipher a Caesar-enciphered mesage
trying all possible keys and checking if the
beginning of the decrypted messages matches one of
the cribs. If so, return the key and return the
deciphered message in the dec parameter.
Preconditions: cip is a char array of maximum
length MAXMSGLEN which contains the cipher
message; dec is a char array of length MAXMSGLEN.
Postconditions: Returns the key if the deciphered
message begins with a crib; returns '\0'
otherwise. If the key is non-zero, the
deciphered message is returned in dec.
******************************************************/

char SolveCipher(const char cip[], char dec[]);





What am I doing wrong?
If you want the Decipher function to be able to work with const arrays you must change the Cip parameter to const char Cip[]
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/174351/
Topic archived. No new replies allowed.