I was wondering if someone could run this into their compiler for me to see if it runs and works. The lab I was working in closed before I could complete this, so I had to try and write the rest in word after I loaded it from my disk. I don't have Visual Studio or any compiler here at my home pc. Any assistance would be great, thanks.
#include <iostream>
#include <string.h>
#include <windows.h>
#include <stdio.h>
using namespace std;
class Stack
{
int x;
int OnTop;
int size;
char* S;
public:
Stack(int SizeOfStack = 100);
~Stack();
bool StackIsFull(void);
bool StackIsEmpty(void);
void Push(char x);
char Pop(void);
}
//contructor
Stack();
bool Stack::StackIsFull(void)
{
return OnTop >= size -1;
}
bool Stack::StackIsEmpty(void)
{
return OnTop <0;
}
void Stack::Push(char x)
{
S[++OnTop] = x;
}
char Stack::Pop(void)
{
return S[OnTop--];
}
//Main function
int main()
{
//Declare variables
HANDLE hInputFile;
HANDLE hOutputFile;
HANDLE hInputFileMap;
HANDLE hOutputFileMap;
PVOID pvInputFile;
PVOID pvOutputFile;
DWORD dwInputFileSize = 0;
DWORD dwOutputFileSize = 0;
DWORD dwErr;
char inputFileName [255];
char outputFileName[255];
char cDrome[10];
int iDrome;
bool IsDrome;
int i;
cout<<"Enter origin path and file name: ";
cin>>inputFileName;
cout<<endl<<endl;
cout<<"Enter destination path and file name: ";
cin>>outputFileName;
cout<<endl;
//create handle for input file
hInputFile = CreateFile(inputFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if (hInputFile == INVALID_HANDLE_VALUE)
{
dwErr = GetLastError();
cout<<"Error number: ";
cin>>dwErr;
cout<<endl;
cout<<"Input file could not be opened.";
cout<<endl;
cout<<endl;
return(FALSE);
}
//create handle for input file mapping
hInputFileMap = CreateFileMapping(hInputFile, NULL, PAGE_READONLY, 0, 0, NULL);
if (hInputFileMap == NULL)
{
dwErr = GetLastError();
cout<<"Error number: ";
cin>>dwErr;
cout<<endl;
CloseHandle(hInputFile);
return(FALSE);
}
//create mapped view of the input file
pvInputFile = MapViewOfFile(hInputFileMap, FILE_MAP_READ, 0, 0, 0);
if (pvInputFile == NULL)
{
dwErr = GetLastError();
cout<<"Error number: ";
cin>>dwErr;
cout<<endl;
cout<<"Could not map view of the input file";
cout<<endl;
CloseHandle(hInputFileMap);
CloseHandle(hInputFile);
return (FALSE);
}
//determine size of the input file and compute appropriate size for output
dwInputFileSize = GetFileSize(hInputFile, NULL);
//set string pointer to the first address of the input file
PSTR pchANSI = (PSTR) pvInputFile;
//determine the exact size needed for the output file
for (i = 0; i < (int)dwInputFileSize; i++)
{
iDrome = (int)pchANSI[i];
itoa(iDrome, cDrome, 10);
dwOutputFileSize = dwOutputFileSize + strlen(cDrome) + 1;
}
//subtract one fm the size to eliminate the last space
dwOutputFileSize = dwOutputFileSize - 1;
//create handle to the output file
hOutputFile = CreateFile(hOutputFilename, GENERIC_WRITE | GENERIC_READ, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
if (hOutputFile == INVALID_HANDLE_VALUE)
{
dwErr = GetLastError();
cout<<"Error number: ";
cin>>dwErr;
cout<<endl;
cout<<"Output file could not be created.";
cout<<endl;
cout<<endl;
UnmapViewOfFile(pvInputFile);
CloseHandle(hInputFileMap);
CloseHandle(hInputFile);
return(FALSE);
}
//create handle to the output file mapping
hOutputFileMap = CreateFileMapping(hOutputFilename,NULL, PAGE_READWRITE, 0,
dwOutputFileSize, NULL);
if (hOutputFileMap == NULL)
{
dwErr = GetLastError();
cout<<"Error number: ";
cin>>dwErr;
cout<<endl;
cout<<"Output file map could not be opened.";
cout<<endl;
cout<<endl;
UnmapViewOfFile(pvInputFile);
CloseHandle(hOutputFile);
CloseHandle(hInputFileMap);
CloseHandle(hInputFile);
return(FALSE);
}
//map view of the output file
pvOutputFile = MapViewOfFile(hOutputFileMap, FILE_MAP_WRITE, 0, 0, 0);
if (pvOutputFile == NULL)
{
dwErr = GetLastError();
cout<<"Error number: ";
cin>>dwErr;
cout<<endl;
cout<<"Could not map view of the output file.";
cout<<endl;
cout<<endl;
UnmapViewOfFile(pvInputFile);
CloseHandle(hOutputFileMap);
CloseHandle(hOutputFile);
CloseHandle(hInputFileMap);
CloseHandle(hInputFile);
return(FALSE);
}
//set string pointer to the first address of the output file
PSTR pchASCII = (PSTR) pvOutputFile;
//determine if word is a palindrome
bool IsDrome(char* c)
{
Stack S;
for (int i = 0; x < strlen(c); i++) S.Push(c[i]);
int i = 0;
while (!S.StackIsEmpty())
if (c[i] != S.Pop()) return false;
return true;
}
}