-2

g++ compiler errors:

encrpyt.cpp: In function ‘int main()’:
encrpyt.cpp:24:35: error: invalid conversion from ‘char*’ to ‘char’ [-fpermissive]
encrpyt.cpp:11:6: error:   initializing argument 1 of ‘void doencrypt(char, char)’ [-fpermissive]
encrpyt.cpp:24:35: error: invalid conversion from ‘char*’ to ‘char’ [-fpermissive]
encrpyt.cpp:11:6: error:   initializing argument 2 of ‘void doencrypt(char, char)’ [-fpermissive]
encrpyt.cpp:28:36: error: invalid conversion from ‘char*’ to ‘char’ [-fpermissive]
encrpyt.cpp:12:6: error:   initializing argument 1 of ‘void dodecrypt(char, char)’ [-fpermissive]
encrpyt.cpp:28:36: error: invalid conversion from ‘char*’ to ‘char’ [-fpermissive]
encrpyt.cpp:12:6: error:   initializing argument 2 of ‘void dodecrypt(char, char)’ [-fpermissive]
encrpyt.cpp: In function ‘void dodecrypt(char*, char)’:
encrpyt.cpp:85:30: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
In file included from encrpyt.cpp:2:0:
/usr/include/c++/4.7/fstream:629:7: error:   initializing argument 1 of ‘std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]’ [-fpermissive]
encrpyt.cpp:89:13: error: statement cannot resolve address of overloaded function
encrpyt.cpp:90:15: error: statement cannot resolve address of overloaded function

code:

#include <iostream>
#include <fstream>
using std::cout;
using std::cin;
using std::endl;
using std::ifstream;
using std::ofstream;
int menu();
void encrypt(ifstream&,ofstream&);
void decrypt(ifstream&, ofstream&);
void doencrypt(char,char);
void dodecrypt(char,char);
int main () {
    int ans=menu();
    char inputfile[100];
    char outputfile[100];
    char outputfile2[100];
    while (ans != 3) {
        if (ans ==1) {
            cout << "Enter input file name." <<endl;
            cin >>inputfile;
            cout << "Enter output file name." <<endl;
            cin >> outputfile;
            doencrypt(inputfile, outputfile);
        } else if (ans==2) {
            cout << "Enter outputfile2 name"<<endl;
            cin >>outputfile2;
            dodecrypt(inputfile, outputfile2);
        } else if (ans!=3) {    
            cout << "Sorry that is not a valid menu choice." <<endl;
            ans=menu();
        }
    }
}

void encrypt (ifstream& input, ofstream& output) {

    if (input && output) {
        while (!input.eof()) {
            char c;
            input.get(c);
            c +10;
            output.put(c);
        }
    } else {
        cout << "Input or output file does not exist" <<endl;
    }
}

void decrypt (ifstream& input, ofstream& output2) {
    if (input && output2) {
        while (!input.eof()) {
            char c;
            input.get(c);
            c-10;
            output2.put(c);
        }
    } else {
        cout <<"Input or output file does not exist" <<endl;
    }
}

int menu () {
    int pick;
    cout << "Pick your menu choice : " <<endl;
    cout << "1.Apply cipher to file" <<endl;
    cout << "2.Decrypt cipher"<<endl;
    cout <<"3.Quit"<<endl;
    cin >> pick;
    return pick;
}   

void doencrypt (char inputfile[], char outputfile[] ) {
    ifstream input(inputfile);
    ofstream output(outputfile);

    encrypt(input, output);

    input.close();
    output.close();
}

void dodecrypt(char inputfile[], char outputfile2) {
    ifstream input(inputfile);
    ofstream output2(outputfile2);

    decrypt(input,output2);

    input.close;
    output2.close;
}
moeCake
  • 512
  • 4
  • 15

4 Answers4

3

The signatures of

void doencrypt(char,char);
void dodecrypt(char,char);

are taken char (so for example just the letter 'a'). You try to give it a char pointer char inputfile[100];

From the context, i assume the above signatures are wrong.

UPDATE: ok the solution is to change the signatures:

void doencrypt(char*,char*);
void dodecrypt(char*,char*);
Marik
  • 119
  • 5
  • 1
    probably should have posted the answer instead of comment lol, OP definitely needs to start from the beginning. [C++ Definitive book guide](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – Mike Feb 07 '14 at 09:52
1

The declarations on the top of the page are wrong. You should use char* as parameters.

void doencrypt(char*,char*);
void dodecrypt(char*,char*);

In the function dodecrypt you also forgot the brackets.

input.close();
output2.close();
drolando
  • 507
  • 2
  • 7
0

You have declared functions which take chars: e.g.

void doencrypt(char,char);

and try to send it a char *:

char inputfile[100];
char outputfile[100];
//...
doencrypt(inputfile, outputfile);

You have a similar problem with dodecrypt

Change the signatures to match the actual functions.

doctorlove
  • 18,872
  • 2
  • 46
  • 62
0

You need to provide the address of c when you read a character:

        input.get(&c); // Line 35
Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82