|
-
May 28th, 2011, 10:12 AM
#61
-
May 28th, 2011, 10:25 AM
#62
Re: Can someone please run this in XP
Ok sorry about that....this is what I am doing and i showed where i put my breakpoint in caps so it stands out ....
Code:
//MAIN FUNCTION
//THIS IS WHERE MY BREAK POINT IS...I HIT F5 AND THEN KEEP HITTING F10 UNTIL I AM AT THE END OF MY PROGRAM
int main(int argc, char *argv[]){
LPCTSTR *myStr1 = (LPCTSTR *)argv[1];
HANDLE readFile, writeFile;
HANDLE readFileMap, writeFileMap;
PVOID pvreadFile, pvwriteFile;
DWORD readFileSize;
string word = "";
list<string> words;
//Test Files -------------------------------------------------------------
char inFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
//argv[1] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
//--------------------------------------------------------------------------
//VERIFYING ARGUMENTS
if(argc=2)
{
readFile = CreateFile(inFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
//IF STATEMENT TO CHECK IF THE READ FILE IS NOT VALID
if(readFile == INVALID_HANDLE_VALUE)
{
//DISPLAY ERROR MESSAGE
std::cout << "Read file could not be opened." << std::endl;
std::cout << "value of GetLastError() is " << GetLastError() << "\n";
return(FALSE);
}
readFileMap = CreateFileMapping(readFile, NULL, PAGE_READONLY, 0, 0, NULL);
//IF STATEMENT TO SEE IF THE READFILEMAP IS NULL
if(readFileMap == NULL)
{
//DISPLAY ERROR MESSAGE
std::cout << "Read file map could not be opened." << std::endl;
CloseHandle(readFile);
return(FALSE);
}
pvreadFile = MapViewOfFile(readFileMap, FILE_MAP_READ, 0, 0, 0);
//IF STATEMENT TO DETERMINE IF PVREADFILE IS NULL
if(pvreadFile == NULL)
{
//DISPLAY ERROR MESSAGE
std::cout << "Could not map view of read file." << std::endl;
CloseHandle(readFileMap);
CloseHandle(readFile);
return(FALSE);
}
//DETERMINE SIZE LIMIT OF INPUT FILE
readFileSize = GetFileSize(readFile, NULL);
//writeFile = CreateFile(argv[2], GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
//LPCTSTR *myStr2 = (LPCTSTR *)argv[2];
//Test Files -------------------------------------------------------------
char outFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Output.txt";
//argv[2] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Output.txt";
//--------------------------------------------------------------------------
writeFile = CreateFile(outFilename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
//IF STATEMENT TO DETERMINE IF WRITE FILE IS VALID OR NOT
if(writeFile == INVALID_HANDLE_VALUE)
{
//DISPLAY ERROR MESSSAGE IF FILE CAN'T BE OPENED
std::cout << "Write file could not be opened." << std::endl;
//std::cout << "argv[1] = " << argv[1] << " argv[2] = " << argv[2] << std::endl;
UnmapViewOfFile(pvreadFile);
CloseHandle(readFileMap);
CloseHandle(readFile);
return(FALSE);
}
writeFileMap = CreateFileMapping(writeFile, NULL, PAGE_READWRITE, 0, readFileSize, NULL);
//IF STATEMENT TO DETERMINE IF WRITE FILE MAP IS NULL
if(writeFileMap == NULL)
{
//DISPLAY ERROR MESSAGE THAT THE WRITE FILE CANNOT BE MAPPED
std::cout << "Write File could not be mapped." << std::endl;
CloseHandle(writeFile);
UnmapViewOfFile(pvreadFile);
CloseHandle(readFileMap);
CloseHandle(readFile);
return(FALSE);
}
pvwriteFile = MapViewOfFile(writeFileMap, FILE_MAP_WRITE, 0,0,0);
//IF STATEMENT IF THE PVWRITEFILE IS NULL
if(pvwriteFile == NULL)
{
//DISPLAY ERROR MESSAGE THAT I COULD NOT OPEN MAP VIEW OF WRITE FILE
std::cout << "Could not open map view of write file." << std::endl;
}
//POINTERS NEED TO BE CREATED
PSTR readptr = (PSTR) pvreadFile;
PSTR writeptr = (PSTR) pvwriteFile;
{
bool ret = isPalindrome( "eve redivider" );
}
//CLEANUP THE FILE
UnmapViewOfFile(pvwriteFile);
UnmapViewOfFile(pvreadFile);
CloseHandle(writeFileMap);
CloseHandle(readFileMap);
CloseHandle(writeFile);
CloseHandle(readFile);
}
//ELSE STATEMENT IF CANNOT FIND FILE
else
//DISPLAY ERROR MESSAGE THAT NO FILE IS GIVEN
cout << "No file given" << endl << endl;
//RETURN A VALUE
return 0;
}
-
May 28th, 2011, 10:48 AM
#63
Re: Can someone please run this in XP
Well...
Now try to comment out this lineand "replay" with debugging.
Victor Nijegorodov
-
May 28th, 2011, 11:18 AM
#64
Re: Can someone please run this in XP
Ok I think I am making progress on this now. I try to debug and it goes through and tries to open but crashes which I expect as I have set this up for memory mapping but when I open with command prompt I get the message "too many arguments given" Just want to see if I am getting close...
Code:
#include <windows.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <list>
using namespace std;
bool isPalindrome(const std::string& s)
{
return s == string(s.rbegin(),s.rend());
}
//MAIN FUNCTION
int main(int argc, char *argv[]){
HANDLE readFile, writeFile;
HANDLE readFileMap, writeFileMap;
PVOID pvreadFile, pvwriteFile;
DWORD readFileSize;
string word = "";
list<string> words;
//Test file
char inFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
//VERIFYING ARGUMENTS
if(argc == 1 )
{
cout << "opening for read: " << argv[1] << endl;
readFile = CreateFile(inFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
//IF STATEMENT TO CHECK IF THE READ FILE IS NOT VALID
if(readFile == INVALID_HANDLE_VALUE)
{
//DISPLAY ERROR MESSAGE
cout << "Read file could not be opened. Error code: " << GetLastError() << endl;
return(FALSE);
}
readFileMap = CreateFileMapping(readFile, NULL, PAGE_READONLY, 0, 0, NULL);
//IF STATEMENT TO SEE IF THE READFILEMAP IS NULL
if(readFileMap == NULL)
{
//DISPLAY ERROR MESSAGE
cout << "Read file map could not be opened. Error code: " << GetLastError() << endl;
CloseHandle(readFile);
return(FALSE);
}
pvreadFile = MapViewOfFile(readFileMap, FILE_MAP_READ, 0, 0, 0);
//IF STATEMENT TO DETERMINE IF PVREADFILE IS NULL
if(pvreadFile == NULL)
{
//DISPLAY ERROR MESSAGE
cout << "Could not map view of read file. Error code: " << GetLastError() << endl;
CloseHandle(readFileMap);
CloseHandle(readFile);
return(FALSE);
}
//DETERMINE SIZE LIMIT OF INPUT FILE
readFileSize = GetFileSize(readFile, NULL);
cout << "Opening for write: " << argv[2] << endl;
//writeFile = CreateFile(argv[2], GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
//test file
char outFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Output.txt";
writeFile = CreateFile(outFilename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
//IF STATEMENT TO DETERMINE IF WRITE FILE IS VALID OR NOT
if(writeFile == INVALID_HANDLE_VALUE)
{
//DISPLAY ERROR MESSSAGE IF FILE CAN'T BE OPENED
cout << "Write file could not be opened. Error code: " << GetLastError() << endl;
//cout << "argv[1] = " << argv[1] << " argv[2] = " << argv[2] << endl;
UnmapViewOfFile(pvreadFile);
CloseHandle(readFileMap);
CloseHandle(readFile);
return(FALSE);
}
writeFileMap = CreateFileMapping(writeFile, NULL, PAGE_READWRITE, 0, readFileSize, NULL);
//IF STATEMENT TO DETERMINE IF WRITE FILE MAP IS NULL
if(writeFileMap == NULL)
{
//DISPLAY ERROR MESSAGE THAT THE WRITE FILE CANNOT BE MAPPED
cout << "Write File could not be mapped. Error code: " << GetLastError() << endl;
CloseHandle(writeFile);
UnmapViewOfFile(pvreadFile);
CloseHandle(readFileMap);
CloseHandle(readFile);
return(FALSE);
}
pvwriteFile = MapViewOfFile(writeFileMap, FILE_MAP_WRITE, 0,0,0);
//IF STATEMENT IF THE PVWRITEFILE IS NULL
if(pvwriteFile == NULL)
{
//DISPLAY ERROR MESSAGE THAT I COULD NOT OPEN MAP VIEW OF WRITE FILE
cout << "Could not open map view of write file. Error code: " << GetLastError() << endl;
}
//CLEANUP THE FILE
UnmapViewOfFile(pvwriteFile);
UnmapViewOfFile(pvreadFile);
CloseHandle(writeFileMap);
CloseHandle(readFileMap);
CloseHandle(writeFile);
CloseHandle(readFile);
}
//ELSE STATEMENT IF CANNOT FIND FILE
else
{
//DISPLAY ERROR MESSAGE THAT NO FILE IS Given
switch( argc )
{
case 0:
cout << "No arguments given" << endl;
break;
case 1:
cout << "No read file or write file given" << endl;
break;
case 2:
cout << "No write file given" << endl;
break;
default:
cout << "too many arguments given." << endl;
}
}
//cout << "Arg 0 = file to read" << endl;
//cout << "Arg 1 = file to write to" << endl;
//RETURN A VALUE
return 0;
}
-
May 28th, 2011, 11:41 AM
#65
Re: Can someone please run this in XP
Why didn't you do what I asked you? (about commenting out a line in your previous code snippet)
Why did you show us a new code snippet until you have solved the problem with a previous one? 
Why in the world do you ask for some help but then ignore the answers?
Victor Nijegorodov
-
May 28th, 2011, 11:56 AM
#66
Re: Can someone please run this in XP
Sorry I commented out the line but did not let me run it
Its the same program but wanted to try something else
I did however get it to try opening but after doing so it crashes...Here is what I changed everything to...
Code:
#include <windows.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <list>
using namespace std;
bool isPalindrome(const std::string& s)
{
return s == string(s.rbegin(),s.rend());
}
//MAIN FUNCTION
int main(int argc, char *argv[])
{
HANDLE readFile, writeFile;
HANDLE readFileMap, writeFileMap;
PVOID pvreadFile, pvwriteFile;
DWORD readFileSize;
string word = "";
list<string> words;
//Test file
//char inFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
char inFilename[] = "C:\\Palindrome\\Debug\\Input.txt";
//VERIFYING ARGUMENTS
if(argc == 1 )
{
cout << "opening for read: " << argv[1] << endl;
readFile = CreateFile(inFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
//IF STATEMENT TO CHECK IF THE READ FILE IS NOT VALID
if(readFile == INVALID_HANDLE_VALUE)
{
//DISPLAY ERROR MESSAGE
cout << "Read file could not be opened. Error code: " << GetLastError() << endl;
return(FALSE);
}
readFileMap = CreateFileMapping(readFile, NULL, PAGE_READONLY, 0, 0, NULL);
//IF STATEMENT TO SEE IF THE READFILEMAP IS NULL
if(readFileMap == NULL)
{
//DISPLAY ERROR MESSAGE
cout << "Read file map could not be opened. Error code: " << GetLastError() << endl;
CloseHandle(readFile);
return(FALSE);
}
pvreadFile = MapViewOfFile(readFileMap, FILE_MAP_READ, 0, 0, 0);
//IF STATEMENT TO DETERMINE IF PVREADFILE IS NULL
if(pvreadFile == NULL)
{
//DISPLAY ERROR MESSAGE
cout << "Could not map view of read file. Error code: " << GetLastError() << endl;
CloseHandle(readFileMap);
CloseHandle(readFile);
return(FALSE);
}
//DETERMINE SIZE LIMIT OF INPUT FILE
readFileSize = GetFileSize(readFile, NULL);
cout << "Opening for write: " << argv[2] << endl;
//writeFile = CreateFile(argv[2], GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
//test file
char outFilename[] = "C:\\Palindrome\\Debug\\Output.txt";
//char outFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Output.txt";
writeFile = CreateFile(outFilename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
//IF STATEMENT TO DETERMINE IF WRITE FILE IS VALID OR NOT
if(writeFile == INVALID_HANDLE_VALUE)
{
//DISPLAY ERROR MESSSAGE IF FILE CAN'T BE OPENED
cout << "Write file could not be opened. Error code: " << GetLastError() << endl;
//cout << "argv[1] = " << argv[1] << " argv[2] = " << argv[2] << endl;
UnmapViewOfFile(pvreadFile);
CloseHandle(readFileMap);
CloseHandle(readFile);
return(FALSE);
}
writeFileMap = CreateFileMapping(writeFile, NULL, PAGE_READWRITE, 0, readFileSize, NULL);
//IF STATEMENT TO DETERMINE IF WRITE FILE MAP IS NULL
if(writeFileMap == NULL)
{
//DISPLAY ERROR MESSAGE THAT THE WRITE FILE CANNOT BE MAPPED
cout << "Write File could not be mapped. Error code: " << GetLastError() << endl;
CloseHandle(writeFile);
UnmapViewOfFile(pvreadFile);
CloseHandle(readFileMap);
CloseHandle(readFile);
return(FALSE);
}
pvwriteFile = MapViewOfFile(writeFileMap, FILE_MAP_WRITE, 0,0,0);
//IF STATEMENT IF THE PVWRITEFILE IS NULL
if(pvwriteFile == NULL)
{
//DISPLAY ERROR MESSAGE THAT I COULD NOT OPEN MAP VIEW OF WRITE FILE
cout << "Could not open map view of write file. Error code: " << GetLastError() << endl;
}
//CLEANUP THE FILE
UnmapViewOfFile(pvwriteFile);
UnmapViewOfFile(pvreadFile);
CloseHandle(writeFileMap);
CloseHandle(readFileMap);
CloseHandle(writeFile);
CloseHandle(readFile);
}
//ELSE STATEMENT IF CANNOT FIND FILE
else
{
//DISPLAY ERROR MESSAGE THAT NO FILE IS Given
switch( argc )
{
case 0:
cout << "No arguments given" << endl;
break;
case 1:
cout << "No read file or write file given" << endl;
break;
case 2:
cout << "No write file given" << endl;
break;
default:
cout << "too many arguments given." << endl;
}
}
//cout << "Arg 0 = file to read" << endl;
//cout << "Arg 1 = file to write to" << endl;
//RETURN A VALUE
return 0;
}
-
May 28th, 2011, 12:01 PM
#67
Re: Can someone please run this in XP
Where did it crash? on what line of your code snippet? And how exactly did it crash?
Victor Nijegorodov
-
May 28th, 2011, 12:09 PM
#68
Re: Can someone please run this in XP
this is what I did...
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Bryan>cd C:\Palindrome\Debug
C:\Palindrome\Debug>palindrome.exe
opening for read:
C:\Palindrome\Debug>
When I do this it I get a message right away saying palindrome.exe has stopped working...is there a way I can do this by getting rid of the argc and argv as I went over this but just dont understand it that great I am sorry to keep asking pretty much same ???
-
May 28th, 2011, 12:19 PM
#69
Re: Can someone please run this in XP
I asked you to debug
Can't you debug?
Victor Nijegorodov
-
May 28th, 2011, 12:29 PM
#70
Re: Can someone please run this in XP
Code:
//Test file
char inFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
//VERIFYING ARGUMENTS
if(argc == 1 )
{
cout << "opening for read: " << argv[1] << endl;
...
}
argc stands for argument count. if you have only one argument, that would be the path to your exe.
if you write this in your console
Palindorme.exe "Testing.txt"
How many arguments will be passed to your exe? 1 or 2??
I will tell you it is not 1 
argc will = 2
arg0 will be the path to your exe. this is automatic. you will always receive this before any of your arguments.
arg1 will be "Testing.txt"
so if( argc == 1 ) would mean you have ZERO arguments that you passed...
so if I typed this in the console
Palindorme.exe "Testing.txt"
arg[ 0 ] will equal the path to this exe file of yours
arg[ 1 ] will equal the very first argument that you passed.
arg[ 2 ] will be anything else you sent to your exe after "Testing.txt"
here seems to be a good tutorial on this http://www.learncpp.com/cpp-tutorial...ine-arguments/
 Originally Posted by jimJohnson123
is there a way I can do this by getting rid of the argc and argv as I went over this but just dont understand it that great I am sorry to keep asking pretty much same ???
If you want to start without the command line args try this,
Code:
#include <windows.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <list>
using namespace std;
bool isPalindrome( const std::string& s )
{
std::string sReverse = s;
std::reverse( sReverse.begin(), sReverse.end() );
return s == sReverse; // return true if the reverse is the same as non-reverse
}
//MAIN FUNCTION
int main()
{
HANDLE readFile, writeFile;
HANDLE readFileMap, writeFileMap;
PVOID pvreadFile, pvwriteFile;
DWORD readFileSize;
string word = "";
list<string> words;
char inFilename[] = "C:\\Palindrome\\Debug\\Input.txt";
char outFilename[] = "C:\\Palindrome\\Debug\\Input.out.txt";
cout << "opening for read: " << inFilename << endl;
readFile = CreateFile( inFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
//IF STATEMENT TO CHECK IF THE READ FILE IS NOT VALID
if( readFile == INVALID_HANDLE_VALUE )
{
//DISPLAY ERROR MESSAGE
cout << "Read file could not be opened. Error code: " << GetLastError() << endl;
return( FALSE );
}
readFileMap = CreateFileMapping( readFile, NULL, PAGE_READONLY, 0, 0, NULL );
//IF STATEMENT TO SEE IF THE READFILEMAP IS NULL
if( readFileMap == NULL )
{
//DISPLAY ERROR MESSAGE
cout << "Read file map could not be opened. Error code: " << GetLastError() << endl;
CloseHandle( readFile );
return( FALSE );
}
pvreadFile = MapViewOfFile( readFileMap, FILE_MAP_READ, 0, 0, 0 );
//IF STATEMENT TO DETERMINE IF PVREADFILE IS NULL
if( pvreadFile == NULL )
{
//DISPLAY ERROR MESSAGE
cout << "Could not map view of read file. Error code: " << GetLastError() << endl;
CloseHandle( readFileMap );
CloseHandle( readFile );
return( FALSE );
}
//DETERMINE SIZE LIMIT OF INPUT FILE
readFileSize = GetFileSize( readFile, NULL );
cout << "Opening for write: " << outFilename << endl;
//writeFile = CreateFile(outFilename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
writeFile = CreateFile( outFilename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
//IF STATEMENT TO DETERMINE IF WRITE FILE IS VALID OR NOT
if( writeFile == INVALID_HANDLE_VALUE )
{
//DISPLAY ERROR MESSSAGE IF FILE CAN'T BE OPENED
cout << "Write file could not be opened. Error code: " << GetLastError() << endl;
//cout << "inFilename = " << inFilename << " outFilename = " << outFilename << endl;
UnmapViewOfFile( pvreadFile );
CloseHandle( readFileMap );
CloseHandle( readFile );
return( FALSE );
}
writeFileMap = CreateFileMapping( writeFile, NULL, PAGE_READWRITE, 0, readFileSize, NULL );
//IF STATEMENT TO DETERMINE IF WRITE FILE MAP IS NULL
if( writeFileMap == NULL )
{
//DISPLAY ERROR MESSAGE THAT THE WRITE FILE CANNOT BE MAPPED
cout << "Write File could not be mapped. Error code: " << GetLastError() << endl;
CloseHandle( writeFile );
UnmapViewOfFile( pvreadFile );
CloseHandle( readFileMap );
CloseHandle( readFile );
return( FALSE );
}
pvwriteFile = MapViewOfFile( writeFileMap, FILE_MAP_WRITE, 0,0,0 );
//IF STATEMENT IF THE PVWRITEFILE IS NULL
if( pvwriteFile == NULL )
{
//DISPLAY ERROR MESSAGE THAT I COULD NOT OPEN MAP VIEW OF WRITE FILE
cout << "Could not open map view of write file. Error code: " << GetLastError() << endl;
}
//CLEANUP THE FILE
UnmapViewOfFile( pvwriteFile );
UnmapViewOfFile( pvreadFile );
CloseHandle( writeFileMap );
CloseHandle( readFileMap );
CloseHandle( writeFile );
CloseHandle( readFile );
return 0;
}
But you must learn on how to accept args still They can be important later on.., but I would get this running right first and then try to add args... No reason to try too much at once
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000
-
May 28th, 2011, 12:57 PM
#71
Re: Can someone please run this in XP
OK I got my input file to work and it now I do a copy con input.txt and it loads into my input file successfully....
Now when I open my output file it is not doing as it should...I also checked the requirements and I do need argc and argv...can anyone see why my output file is blank as it should be storing palindromes?
Code:
#include <windows.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <list>
using namespace std;
bool isPalindrome(const std::string& s)
{
return s == string(s.rbegin(),s.rend());
}
//MAIN FUNCTION
int main(int argc, char *argv[])
{
HANDLE readFile, writeFile;
HANDLE readFileMap, writeFileMap;
PVOID pvreadFile, pvwriteFile;
DWORD readFileSize;
string word = "";
list<string> words;
//Test file
//char inFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
char inFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
//VERIFYING ARGUMENTS
if(argc = 2 )
{
cout << "opening for read: " << argv[1] << endl;
readFile = CreateFile(inFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
//IF STATEMENT TO CHECK IF THE READ FILE IS NOT VALID
if(readFile == INVALID_HANDLE_VALUE)
{
//DISPLAY ERROR MESSAGE
cout << "Read file could not be opened. Error code: " << GetLastError() << endl;
return(FALSE);
}
readFileMap = CreateFileMapping(readFile, NULL, PAGE_READONLY, 0, 0, NULL);
//IF STATEMENT TO SEE IF THE READFILEMAP IS NULL
if(readFileMap == NULL)
{
//DISPLAY ERROR MESSAGE
cout << "Read file map could not be opened. Error code: " << GetLastError() << endl;
CloseHandle(readFile);
return(FALSE);
}
pvreadFile = MapViewOfFile(readFileMap, FILE_MAP_READ, 0, 0, 0);
//IF STATEMENT TO DETERMINE IF PVREADFILE IS NULL
if(pvreadFile == NULL)
{
//DISPLAY ERROR MESSAGE
cout << "Could not map view of read file. Error code: " << GetLastError() << endl;
CloseHandle(readFileMap);
CloseHandle(readFile);
return(FALSE);
}
//DETERMINE SIZE LIMIT OF INPUT FILE
readFileSize = GetFileSize(readFile, NULL);
cout << "Opening for write: " << argv[2] << endl;
//writeFile = CreateFile(argv[2], GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
//test file
char outFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome";
//char outFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Output.txt";
writeFile = CreateFile(outFilename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
//IF STATEMENT TO DETERMINE IF WRITE FILE IS VALID OR NOT
if(writeFile == INVALID_HANDLE_VALUE)
{
//DISPLAY ERROR MESSSAGE IF FILE CAN'T BE OPENED
cout << "Write file could not be opened. Error code: " << GetLastError() << endl;
//cout << "argv[1] = " << argv[1] << " argv[2] = " << argv[2] << endl;
UnmapViewOfFile(pvreadFile);
CloseHandle(readFileMap);
CloseHandle(readFile);
return(FALSE);
}
writeFileMap = CreateFileMapping(writeFile, NULL, PAGE_READWRITE, 0, readFileSize, NULL);
//IF STATEMENT TO DETERMINE IF WRITE FILE MAP IS NULL
if(writeFileMap == NULL)
{
//DISPLAY ERROR MESSAGE THAT THE WRITE FILE CANNOT BE MAPPED
cout << "Write File could not be mapped. Error code: " << GetLastError() << endl;
CloseHandle(writeFile);
UnmapViewOfFile(pvreadFile);
CloseHandle(readFileMap);
CloseHandle(readFile);
return(FALSE);
}
pvwriteFile = MapViewOfFile(writeFileMap, FILE_MAP_WRITE, 0,0,0);
//IF STATEMENT IF THE PVWRITEFILE IS NULL
if(pvwriteFile == NULL)
{
//DISPLAY ERROR MESSAGE THAT I COULD NOT OPEN MAP VIEW OF WRITE FILE
cout << "Could not open map view of write file. Error code: " << GetLastError() << endl;
}
//CLEANUP THE FILE
UnmapViewOfFile(pvwriteFile);
UnmapViewOfFile(pvreadFile);
CloseHandle(writeFileMap);
CloseHandle(readFileMap);
CloseHandle(writeFile);
CloseHandle(readFile);
}
//ELSE STATEMENT IF CANNOT FIND FILE
else
{
//DISPLAY ERROR MESSAGE THAT NO FILE IS Given
switch( argc )
{
case 0:
cout << "No arguments given" << endl;
break;
case 1:
cout << "No read file or write file given" << endl;
break;
case 2:
cout << "No write file given" << endl;
break;
default:
cout << "too many arguments given." << endl;
}
}
//cout << "Arg 0 = file to read" << endl;
//cout << "Arg 1 = file to write to" << endl;
//RETURN A VALUE
return 0;
}
-
May 28th, 2011, 12:59 PM
#72
Re: Can someone please run this in XP
if(argc = 2 ) is wrong. you don't assign a value to argc use the other operator meant for comparison
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000
-
May 28th, 2011, 01:04 PM
#73
Re: Can someone please run this in XP
thanks....changed to argc==2 and input still works fine but output has a blank file....could my palindrome not be correct?
-
May 28th, 2011, 01:08 PM
#74
Re: Can someone please run this in XP
if(argc == 2 )
cout << "Opening for write: " << argv[2] << endl;
Consider that a buffer overrun
Again... debugging will tell you this... or it should. You are trying to modify code that was good when you simply need to learn how to pass args right....
Last edited by Joeman; May 28th, 2011 at 01:13 PM.
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000
-
May 28th, 2011, 01:13 PM
#75
Re: Can someone please run this in XP
No I dont see it anywhere when I put it == 2 or if I put argc > 1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|