CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 6 FirstFirst 12345 ... LastLast
Results 16 to 30 of 84
  1. #16
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Can someone please run this in XP

    Please, read the post#6
    Victor Nijegorodov

  2. #17
    Join Date
    May 2010
    Posts
    76

    Re: Can someone please run this in XP

    By doing so this is the line I am getting the error in but cannot figure out why...


    readFile = CreateFile(argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

    I believe it has something to do with argv[1]

  3. #18
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: Can someone please run this in XP

    When you run from the command line, the argument that you give
    the executable will be argv[1]. What are you entering ?
    Code:
    your_exe filename
    argv[1] = filename

    As I mentioned in my previous post, remove tghe argc/argv coding
    and hardwire a filename. Does your code work ?

  4. #19
    Join Date
    May 2010
    Posts
    76

    Re: Can someone please run this in XP

    I am not sure what I even am supposed to run from the command prompt

  5. #20
    Join Date
    Aug 2008
    Posts
    902

    Re: Can someone please run this in XP

    jimJohnson123, open up your command prompt and try actually using the program the way it was designed to be used. You type:

    name_of_program.exe name_of_file_to_process

    When you execute the programs from the command line, and supply the name of your file, then argc will be > 1.

    The reason you've been failing is because you are trying to run the thing from the MSVC IDE!

  6. #21
    Join Date
    May 2010
    Posts
    76

    Re: Can someone please run this in XP

    OK I guess I am just not doing command prompt right as this is what I did...

    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\Palindrome

    C:\Users\Bryan\Documents\CSI 345\Palindrome\Palindrome>palindrome.exe
    'palindrome.exe' is not recognized as an internal or external command,
    operable program or batch file.

    C:\Users\Bryan\Documents\CSI 345\Palindrome\Palindrome>


    My program is located here...

    C:\Users\Bryan\Documents\CSI 345\Palindrome\Palindrome

    The following files are located here...

    debug(folder), Palindrome (C++ source), Input(text document), Palindrome (VC project), palindrome.vcxproj (VC++ Project Filter File), Palindrome.vcxproj(Visual Studio Project User Options File)

    I just need someone to show me how to run this through command prompt and please only positive feedback I do not want anyone responding with rude comments(not saying anyone has just want to be upfront) My reasoning is this is probably extremely simple for most of u guys thats all

  7. #22
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: Can someone please run this in XP

    You're right, it's very simple. Judging from post #15,
    'Palindrome.exe': Loaded 'C:\Users\Bryan\Documents\CSI 345\Palindrome\Debug\Palindrome.exe', Symbols loaded.
    your executable is in "'C:\Users\Bryan\Documents\CSI 345\Palindrome\Debug\"

    So, open a command prompt:

    C:
    CD \Users\Bryan\Documents\CSI 345\Palindrome\Debug\
    Palindrome.exe <NAMEOFTHEFILE>

  8. #23
    Join Date
    May 2010
    Posts
    76

    Re: Can someone please run this in XP

    I did that with input.txt and get the error read file map could not be opened so it does not it past the first section

  9. #24
    Join Date
    May 2010
    Posts
    76

    Re: Can someone please run this in XP

    I think I read on how to fix this....


    If I wanted to how would I cast argv[1] and argv[2] to a LPCTSTR data type?

  10. #25
    Join Date
    Jun 2008
    Posts
    592

    Re: Can someone please run this in XP

    Quote Originally Posted by jimJohnson123
    If I wanted to how would I cast argv[1] and argv[2] to a LPCTSTR data type?
    just like the how your code below does
    Code:
    readFile = CreateFile(argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    CreateFile

    HANDLE WINAPI CreateFile( __in LPCTSTR lpFileName, ..... );

    LPCSTR stands for long pointer const string... basically. The same as const char* which char* is being implicitly casted to.
    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

  11. #26
    Join Date
    May 2010
    Posts
    76

    Re: Can someone please run this in XP

    does that even seem like what needs to be done to fix this or am i reading something that is not the problem

  12. #27
    Join Date
    Jun 2008
    Posts
    592

    Re: Can someone please run this in XP

    Quote Originally Posted by jimJohnson123
    I did that with input.txt and get the error read file map could not be opened so it does not it past the first section
    If your output didn't read "No file given", it will try to open the file. You will have to use GetLastError() after the last call that failed to return the error code. Look up the number at http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx to find why it didn't work
    Last edited by Joeman; May 24th, 2011 at 12:33 AM.
    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

  13. #28
    Join Date
    Jun 2008
    Posts
    592

    Re: Can someone please run this in XP

    I did read
    Code:
            if(argc>1)
            {
                  // stuff I don't care about
            }
    which seems to be misplaces and should be deleted, but go ahead and run this modified version
    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;
    
        //VERIFYING ARGUMENTS
        if(argc == 3 )
        {
            cout << "opening for read: " << argv[1] << endl;
            readFile = CreateFile(argv[1], 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);
            writeFile = CreateFile(argv[2], 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 << "Way 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;
    }
    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

  14. #29
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Can someone please run this in XP

    Quote Originally Posted by jimJohnson123 View Post
    does that even seem like what needs to be done to fix this or am i reading something that is not the problem
    You still haven't proven you understand the very simple basics.

    Where does argc get its value? If you don't understand or can't answer that question, then there is no way you are going to understand the program that you supposedly wrote.

    Regards,

    Paul McKenzie

  15. #30
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Can someone please run this in XP

    Quote Originally Posted by Joeman View Post
    which seems to be misplaces and should be deleted, but go ahead and run this modified version
    If the OP doesn't understand a simple if/else, or know where argc gets its values and what it means, then the only thing left is to give the answer away and have it copied, and this board has a policy of not giving answers away.

    Regards,

    Paul McKenzie

Page 2 of 6 FirstFirst 12345 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured