Please excuse my laziness, your code worked for me when I broke it down...so I just rewrote it. :P
Code:
#include <iostream>
using namespace std;
void cryptString(char *str, const char crypt);
char cryptChar(char ch, const char crypt);
/* argv should have three parameters: The file name,
** the line argument to determine encrypt or decrypt,
** and the line argument to do the opposite of the
** previous argument, just to make sure it worked.
**
** Line arguments are tested as e and d, but change
** the test and you can change the argument.
*/
int main(int argc, char *argv[])
{ char message[1000] = {0};
if( argc != 3 )
// Never do this, always let the user know
return EXIT_FAILURE;
cout << "Enter a message to crypt: " << flush;
cin.getline( message, 1000, '\n' );
// Before
cout << message << endl;
cryptString(message, *argv[1]);
// After
cout << message << endl;
cryptString(message, *argv[2]);
// Back to original
cout << message << endl;
getchar();
return EXIT_SUCCESS;
}
void cryptString(char *str, const char crypt)
{
while (*str != '\0') {
*str = cryptChar(*str, crypt);
str++;
}
}
char cryptChar(char ch, const char crypt)
{
/* I used a simple rotate 13 encryption
** but you can use whatever you want
*/
if( crypt == 'e' )
ch += 13;
else if( crypt == 'd' )
ch -= 13;
return ch;
}
Your error sounds like it may be implementation defined.
-Prelude