I am finishing up a program and have a few issues. I get the following error twice in the program...

error C2664: 'CreateFileW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Can someone please show and explain to me how to set up a cast for this program....

#include <windows.h>
#include <iostream>
#include <stack>
#include <queue> 
using namespace std;



//START THE MAIN FUNCTION
int main(int argc, char *argv[])
{
	//BEGIN THE INPUT FILE MAPPING
	HANDLE hFile;
    HANDLE hFileMap;
    PVOID pvFile;
    DWORD dwFileSize;
    int i = 0;
	
	//HAVE USER ENTER THE PATH FOLLOWED BY THE FILE NAME
	cout<<"Please enter the path and filename: ";
	cout << endl;

	//Test for validity
	char hFilename[] = "C:\\Users\Bryan\Documents\CSI 345\Palindrome\Input.txt"; 
	argv[1] = "C:\\Users\Bryan\Documents\CSI 345\Palindrome\Input.txt"; 
  
	//ALLOW THE HFILE TO RETURN A HANDLE TO THE OPEN FILE
	
	hFile = CreateFile(argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

	//IF STATEMENT TO CHECK IF FILE CAN BE OPENED
    if (hFile == INVALID_HANDLE_VALUE)
      {
			//DISPLAY MESSAGE THAT FILE CANNOT BE OPEN
            cout << "File could not be opened.";
            return(FALSE);
      }
      
      //OPENS A FILE MAPPED OBJECT
      hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);

	  //IF STATEMENT TO SEE IF HFILEMAP CAN BE OPENED
      if (hFileMap == NULL)
      {
			//DISPLAY MESSAGE THAT THIS FILE CANNOT BE OPENED
            cout << "File map could not be opened";
            CloseHandle(hFile);
            return(FALSE);
      }
      
      //GIVES ADDRESS FOR DATA FILE
      pvFile = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0);

	  //IF STATEMENT TO SEE IF PV FILE CAN BE OPENED
      if (pvFile == NULL)
      {
			//DISPLAY MESSAGE THAT THIS FILE CANNOT BE OPENED
            cout << "Could not map view of File";
            CloseHandle(hFileMap);
            CloseHandle(hFile);
            return(FALSE);
      }

 
      //GIVES THTE SIZE OF THE FILE    
      dwFileSize = GetFileSize(hFile, NULL);

    //BEGIN OUTPUT FILE MAPPING
	HANDLE oFile;
    HANDLE oFileMap;
    PVOID pvOFile;
    DWORD dwOFileSize;

	//TEST FOR VALIDITY
	char oFilename[] = "C:\\Users\Bryan\Documents\CSI 345\Palindrome\Output.txt";  
    argv[2] = "C:\\Users\Bryan\Documents\CSI 345\Palindrome\Output.txt";

   
	//HAVE USER ENTER THE PATH FOLLOWED BY THE FILE NAME
    cout << "Please enter path and filename: ";
	cout << endl;

	//ALLOW THE oFILE TO RETURN A HANDLE TO THE OPEN FILE
    oFile = CreateFile(oFilename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

	//IF STATEMENT TO CHECK IF FILE CAN BE OPENED
	if (oFile == INVALID_HANDLE_VALUE)
	{  
		//DISPLAY A MESSAGE FILE CANNOT BE OPENED
		cout << "outFile could not be opened.";
        return(FALSE);
     }

	//OPENS A FILE MAPPED OBJECT
	oFileMap = CreateFileMapping(oFile, NULL, PAGE_READWRITE, 0, dwFileSize, NULL);

	//OPENS A FILE MAPPED OBJECT
    if (oFileMap == NULL)
    {

		//DISPLAY A MESSAGE FILE CANNOT BE OPENED
        cout << "File map could not be opened";
        CloseHandle(oFile);
        return(FALSE);
    }

	//GIVES ADDRESS FOR DATA FILE
    pvOFile = MapViewOfFile(oFileMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
 
	//IF STATEMENT TO SEE IF PV FILE CAN BE OPENED
    if (pvOFile == NULL)
    {
		//DISPLAY A MESSAGE FILE CANNOT BE OPENED
		cout << "Could not map view of File";
        CloseHandle(hFileMap);
        CloseHandle(hFile);
        return(FALSE);
      }

      //INPUT FILE SIZE AND OUTPUT FILE SIZE MUST MATCH UP
	  dwOFileSize = dwFileSize;
	  
	  //TEST THE SIZE OF THE FILE
      cout << "The file size is: " << dwOFileSize << endl;


      // pointer to the beginning address
      PSTR hptr = (PSTR) pvFile;
      PSTR optr = (PSTR) pvOFile;


	  // CHECK FOR PALINDROMES
	  char check;
	  bool palindrome = false;
	  char testArray [600];
	  char testOutArray [600];
	  int icount = 0;
	  int ocount = dwOFileSize;
	  int g = 0;
	  stack<char> stack;  
	  queue<char> queue;

	 //Begin for statement 
	 for (i = 0; i < dwFileSize; i++) 
    {
		hptr[i];
	 }
	  for (i = 0; i < dwFileSize; i++) 
    {
		stack.push(testArray[i]);
	 }


		//CHECKS TO MAKE SURE A SPACE IS NOT FOUND
	    //IF SPACE IS NOT FOUND BEGIN TO PUSH ALL CHARACTERS TO ARRAYS
		if (hptr[i] != ' ') 
		{
			stack.push(testArray[i]);
			queue.push(testOutArray[i]);
		
			//TEST OUTPUT
			icount++;	
		}
		//IF THERE IS A SPACE COMPARE THE CHARACTERS IN REVERSE ORDER 
		if (hptr[i] == ' ')
		{
			//PERFORM WHILE STATEMENT FOR WHEN THTE STACK IS NOT EMPTY
			while (!stack.empty())
			{
					stack.top() = testArray[g];
					g ++;
					stack.pop() ;
					cout << "The top is:" << stack.top() << endl;

					ocount --;
					int i = 0;
			}
				
		}
	  }

Recommended Answers

All 8 Replies

I looked at both sites but I still do not know what I am supposed to change

try this first quote...

"I'm assuming your using Visual Studio.
The easiest solution to this problem is to change your solution settings from Unicode to Multi-btye.
VS sets windows applications to default to unicode. While unicode "may" be better, it certainly is more difficult for beginning programming and requires explicit conversions.

Right click on your Project, select Properties. Configuration Properties/General
And Character Set to Multi-Byte."

That did work...but I am not sure what it is supposed to run. IF I post the instructions to the assignment can someone please just verify I have everything right before turning it in?

Create a utility that transfers words that are palindromes in the input file into the output file. Place a space between each palindrome written to the output file.
The input path and file name and the output path and file name must be gathered at runtime from the user. This can be accomplished via command line inputs (see argv and argc parameters in the main() function).
The program must use memory-mapped file input/output.
The contents of the input file must not be changed by your program (read only).
The definition of a palindrome, for purposes of this programming assignment, is a word which reads the same backward or forward. Examples of palindromes are mom, pop, kayak, noon, radar, and racecar.
While there are a number of methods available to test to see if a word is a palindrome, the most common method is to use a stack. Character[0] of the original string can be compared with character[n-1]. The next comparison would address character[1] with character[n-2]. Comparison continues until all characters are compared (the stack is empty) or there is an inequality (the word is not a palindrome).
The output file should contain only those words that are palindromes from the input file. Each word in the output file should be separated by a space.
Since the length of the output file is determined at runtime, and there is no way to predict how many palindromes will be present in the input file (without actually performing the test), there is no means to accurately predict the output file size required. Set the output file size to the input file size.

Could I please get a quick example on how it should look?

LPCTSTR pstr = _T("c:\\filename.txt");

TCHAR* pstr = _T("c:\\filename.txt);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.