Dear friends,
I have previosly posted part of this code. I am improving on it to take its input from a file and output to another file. I am also trying to make it more user interactive.
I achieved writing the program output to a file using:
ofstream file_op("c:\\file.txt",ios::app);
file_op<<n;
file_op.close();
I am using CV++ 6.0 to compile this code. The following errors are reported. Can someone please help me
learn how to remove these errors.
Compiling...
encrypt2Function.cpp
C:\encrypt2Function.cpp(36) : error C2664: '__thiscall std::basic_ifstream<char,struct std::char_traits<char> >::std::basic_ifstream<char,struct std::char_traits<char> >(const char *,int)' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\encrypt2Function.cpp(80) : error C2181: illegal else without matching if
C:\encrypt2Function.cpp(100) : error C2601: 'Interface' : local function definitions are illegal
C:\encrypt2Function.cpp(131) : error C2601: 'EncDec' : local function definitions are illegal
Error executing cl.exe.
encrypt2Function.obj - 4 error(s), 0 warning(s)
My code is
Code:
#include <iostream>
#include <string>
#include <time.h>
#include <conio.h>
#include <fstream>
#define DATA 0x378 //Data Register base address
#define STATUS DATA+1 // Status Register address
#define CONTROL DATA+2 //Control Register address
using namespace std;
//Function prototyping
void Interface (ifstream &fin, char (*Secure)(char c));
char EncDec (char c);
//main (): manage file stream extraction
int main ()
{
const int MaxFileNameSize=256;
// prompt and extract the name of the file
cout<<"Enter the name of the file:"<<flush;
char FileName;
//validate the file name provided
ifstream fin (FileName);
if (fin)
{
//we have a valid file, so determine the action
cout<<"The file contents to be made secure through"
<<"bit level transformation (Y,N):"<<flush;
char reply;
cin>>reply;
//process the file according to the user request
switch (reply)
{
case 'Y':
Interface(fin, EncDec);
break;
case 'N':
cout<<"File is left in plain version";
break;
default:
{
cerr<<"Bad request"<<endl;
return 1;
}
}
else
{
cerr<<"Invalid file name:"<<FileName<<endl;
return 1;
}
return 0;
}
//Interface (): Manage the interface to the stream cipher
//using the EncDec () function.
void Interface (ifstream &fin, char (*secure)(char c))
{
//Extract, modify and save one-character-at-a-time
//from the file.
char CurrentChar; //currenrly extracted character
while (fin.get(CurrentChar))
{ //modify and save the current character using
//Secure()
CurrentChar=(*Secure)(CurrentChar);
ofstream file_op("C:\\CodeOutput file_out.txt"), ios::out);
file_op<<CurrentChar;
}
return;
}
//EncDec(): manage writing to and reading from the
//standard parallel port.
char EncDec (char c )
{
char s, n;
_outp(CONTROL,_inp(CONTROL)&0xF0|0x04); /*initialise the
CONTROL port for data input*/
_outp(DATA, s); /*write c to the DATA register*/
clock_t start_time;
start_time=clock();
while ((clock()-start_time)<0.25*CLK_TCK);//propagation delay time
n=(_inp(STATUS)&0xF0); /* read MSnibble*/
n=n|(_inp(CONTROL)&0x0F);/*Read LSnibble*/
n=n^0x84; /*toggle bit 2 and 7 */
/*pins 11(bit 7)-BUSY- is hardware inverted. Pin 16 has been inverted by the external hardware*/
return s;
}
}