Compiler Error- Overloaded function, invalid conversion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • enbulldog
    New Member
    • Nov 2006
    • 1

    #1

    Compiler Error- Overloaded function, invalid conversion

    I am working on a program to "encrypt" a text file supplied by the user, and writing to another file also given by the user. I am very new to programming and am having trouble passing information from file to program and back to file. I am close, but I have comiler errors. Here is my code so far:


    Code:
    #include <iostream>
    #include <cctype>
    #include <fstream>
    #include <iomanip>
    using namespace std;
    
    //Function: displayHeader
    //Description: Outputs program header to screen
    //Inputs: None
    //Outputs: Header to screen
    //Usage: displayHeader()
    void displayHeader();
    
    void getFile(char& fileIn, char& fileOut);
    
    char charShift (char toEncrypt);
    
    char encrypt(char symbol);
    
    bool firstHalf(char symbol);
    
    int main()
    {
      char fileIn[13];
      char fileOut[13];
      char runAgain;
      ifstream file1;
      ofstream file2;
      displayHeader();
      do
      {
        void getFile(char& fileIn, char& fileOut);
        ifstream file1(fileIn[]);
        if (!file1||!file2)
        {
          cout << "Error opening input file." << endl;
        }
        char encrypt(file1);
        file1.close;
        file2.close;
        cout << "Would you like to run program again? (y/n)" << endl;
        cin >> runAgain;
      }
      while (runAgain=='Y'||runAgain=='y');
    }
      
    void getFile(char& fileIn, char& fileOut)
    {
      cout << "Please enter name of file to be encrypted." << endl;
      cin >> fileIn;
      cout << "Please enter file to write to." << endl;
      cin >> fileOut;
    }
    
    char encrypt(char symbol)
    {
      char encryptChar;
      char nextCh;
      nextCh=symbol;
      file1.get(nextCh);
      while (!file1.eof())
      {
        if (isalpha(nextCh))
        {
          encyptChar=charShift(nextCh);
          file2 << encryptChar;
        }
        else
        {
          file2 << nextCh;
        }
      }
    }
    
    char charShift(char toEncrypt)
    {
      if (firstHalf(toEncrypt))
      {
        return toEncrypt+13;
      }
      else
      {
        return toEncrypt-13;
      }
    }
    
    bool firstHalf(char symbol)
    {
     if((symbol>='A'&&<='M')||(symbol>='a'&&<='m'))
      {
        return 1;
      }
      else
      {
        return 0;
      }
    }
    To which I receive these following compiler errors:

    Here (Photo)

    any help would be useful, thanks
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Code:
        void getFile(char& fileIn, char& fileOut);
    This is not a function call it is a function definition and as such does nothing so fileIn and fileOut are still uninitialised. It should be
    Code:
        getFile(fileIn, fileOut);
    Code:
        ifstream file1(fileIn[]);
    The square brackets are a syntax error in this line remove them

    Code:
      
    void getFile(char& fileIn, char& fileOut)
    {
     <snipped>
    }
    You have declared references to a char but are trying to pass a char array into this function, either declare them as pointers
    Code:
      
    void getFile(char *fileIn, char *fileOut)
    {
     <snipped>
    }
    or declare them as references to char array

    Code:
      
    void getFile(char (&fileIn)[13], char (&fileOut)[13])
    {
     <snipped>
    }
    Code:
        char encrypt(file1);
    the char is wrong and you pass a char array to encrypt

    Code:
    char encrypt(char symbol)
    {
        <snipped>
    }
    But it is defined as accepting a char

    Comment

    Working...