Re: Can someone please run this in XP
Could you at least tell me if im on the right track...i dont need a big explanation if u dont want even a yes or no with this post is fine....
//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>3)
Re: Can someone please run this in XP
Quote:
Originally Posted by
jimJohnson123
Could you at least tell me if im on the right track...i dont need a big explanation if u dont want even a yes or no with this post is fine....
//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>3)
You still don't seem to know what argc and argv do. Have you even looked at their documentation or checked their values in the debugger? Seems like you'd save yourself a lot of grief if you did.
Re: Can someone please run this in XP
1. You do not set argc and argv
2. if you want to use them, you should run from the command prompt
3. If, from the comand prompt, you type:
your_code.exe aaa bbb ccc
then
argc = 4
argv[0] = "your_code.exe"
argv[1] = "aaa"
argv[2] = "bbb"
argv[3] = "ccc"
Re: Can someone please run this in XP
Quote:
Originally Posted by
jimJohnson123
Could you at least tell me if im on the right track...i dont need a big explanation if u dont want even a yes or no with this post is fine....
//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>3)
No.
Thats what you asked for - Was that more helpful than a full explanation?
Re: Can someone please run this in XP
well no but i know everyone in the forum has explained this to me as best as they can (which I greatly respect) and still having issues and didnt want to be a burden
Re: Can someone please run this in XP
Sorry to bother again but is this what u mean with hardwire the file names.....
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(int argc, char *argv[]){
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
//LPCTSTR *myStr1 = (LPCTSTR *)argv[1];
if(argc>1)
{
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;
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;
}
Re: Can someone please run this in XP
Yes, but you need to cooment out:
Code:
argv[1] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
Since if you do not supply enough arguments when running from
the command line (or do not run from the command line), that
will be past the bounds of the array.
Also remove the
logic (or set argc equal to 2).
But why don't you just run from the command line ?
Re: Can someone please run this in XP
Ok when you mean running from command line I am doing to change directory (cd0 and going to C:\Users\Bryan\Documents\CSI 345\Palindrome\Debug so I am typing the folliwng in command prompt...
cd C:\Users\Bryan\Documents\CSI 345\Palindrome\Debug and hitting enter...
the name of my input file is input.txt and output file is output txt so I am doing the following...
C:\Users\Bryan\Documents\CSI 345\Palindrome\Debug> palindrome.exe input.txt and get the "read file map could not be opened" I just want to make sure I am doing this part right
Re: Can someone please run this in XP
that is correct.
Is input.txt in the Debug folder ? If not, copy it there.
Re: Can someone please run this in XP
Re: Can someone please run this in XP
I don't use the non-standard I/O, but according to the documentation,
you can call GetLastError() to get extended error info.
So ...
Code:
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);
}
Re: Can someone please run this in XP
Quote:
Originally Posted by
jimJohnson123
yes sir it is in there
On the command line, give the complete path of the input file. Then it doesn't matter where the file is located, as you're giving the entire path to the command line:
Quote:
palindrome C:\Whatever\Whatever2\input.txt
Similar to that.
Regards,
Paul McKenzie
Re: Can someone please run this in XP
Just want to verify but did so and get the same response...
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Bryan>cd C:\Users\Bryan\Documents\CSI 345\Palindrome\Debug
C:\Users\Bryan\Documents\CSI 345\Palindrome\Debug>palindrome.exe C:\Users\Bryan\
Documents\CSI 345\Palindrome\Debug\input.txt
Read file map could not be opened.
C:\Users\Bryan\Documents\CSI 345\Palindrome\Debug>
Re: Can someone please run this in XP
Please, do what I tell you in the post#6. :cool:
Re: Can someone please run this in XP
looks like after debugging it shows that it cannot be opened at
int main(int argc, char *argv[]){
I am guessing this is what needs to be changed? if someone can just say yes or no to this I am goin to see what I can do with it