Thread: Please help clear two errors

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    7

    Please help clear two errors

    Can someone tell me how to clear the final two errors I am rcving on this?

    Errors:
    error C2365: 'palDrome' : redefinition; previous definition was a 'data variable'

    error C2601: 'palDrome' : local function definitions are illegal


    Code:
    //Program description: Palindrome
    
    #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()
    {
    	//use to declare the variables for program
    	HANDLE hInputFile;
    	HANDLE hInputFileMap;
    	PVOID pvInputFile;
    	DWORD dwInputFileSize = 0;
    	char inputFileName [255];
    	HANDLE hOutputFile;
    	HANDLE hOutputFileMap;
    	PVOID pvOutputFile;
    	DWORD dwOutputFileSize = 0;
    	char outputFileName[255];
    	DWORD dwErr;
    	char pDrome[15];
    	int palinDrome;
    	bool palDrome;
    	int i;
    
    	//menu prompt for user
    	cout<<"-----------------------------------------------------------------";
    	cout<<"        Please enter the Input file name for the origin:         ";
    	cin>>inputFileName;
    	cout<<endl;
    	cout<<endl;
    	cout<<"-----------------------------------------------------------------";
    	cout<<"-----------------------------------------------------------------";
    	cout<<"        Please enter the Output file name for the destination:   ";
    	cin>>outputFileName;
    	cout<<endl;
    	cout<<endl;
    	cout<<"-----------------------------------------------------------------";
    
    	//used to create a handle for the input file
    	hInputFile = CreateFile(inputFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING,
    		FILE_ATTRIBUTE_NORMAL, NULL);
    	if (hInputFile == INVALID_HANDLE_VALUE)
    	{
    		dwErr = GetLastError();
    		cout<<"Error occured.  The current error number is ";
    		cin>>dwErr;
    		cout<<".";
    		cout<<endl;
    		cout<<"The input file could not be opened due to error.";
    		cout<<endl;
    		cout<<endl;
    		return(FALSE);
    	}
    
    	//used to create handle for the input file mapping
    	hInputFileMap = CreateFileMapping(hInputFile, NULL, PAGE_READONLY, 0, 0, NULL);
    	if (hInputFileMap == NULL)
    	{
    		dwErr = GetLastError();
    		cout<<"Error occured.  The current error number is ";
    		cin>>dwErr;
    		cout<<".";
    		cout<<endl;
    		cout<<"The input file map could not be viewed.";
    		CloseHandle(hInputFile);
    		return(FALSE);
    	}
    
    	//used tp create a mapped view of the input file
    	pvInputFile = MapViewOfFile(hInputFileMap, FILE_MAP_READ, 0, 0, 0);
    	if (pvInputFile == NULL)
    	{
    		dwErr = GetLastError();
    		cout<<"Error occured.  The current error number is ";
    		cin>>dwErr;
    		cout<<".";
    		cout<<endl;
    		cout<<"The input file map could not be viewed.";
    		cout<<endl;
    		CloseHandle(hInputFileMap);
    		CloseHandle(hInputFile);
    		return (FALSE);
    	}
    
    	//used to determine the size of the input file 
    	dwInputFileSize = GetFileSize(hInputFile, NULL);
    
    	PSTR pchANSI = (PSTR) pvInputFile;
    
    	//used to determine the size for the output file
    	for (i = 0; i < (int)dwInputFileSize; i++)
    	{
    		palinDrome = (int)pchANSI[i];
    		itoa(palinDrome, pDrome, 15);
    		dwOutputFileSize = dwOutputFileSize + strlen(pDrome) + 1;
    	}
    
    	//used to get rid of the last space
    	dwOutputFileSize = dwOutputFileSize - 1;
    
    	//used to create a handle to the output file
    	hOutputFile = CreateFile(outputFileName, GENERIC_WRITE | GENERIC_READ, 0, NULL,
    		CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
    	if (hOutputFile == INVALID_HANDLE_VALUE)
    	{
    		dwErr = GetLastError();
    		dwErr = GetLastError();
    		cout<<"Error occured.  The current error number is ";
    		cin>>dwErr;
    		cout<<".";
    		cout<<endl;
    		cout<<"The output file could not be made due to error.";
    		cout<<endl;
    		cout<<endl;
    
    		UnmapViewOfFile(pvInputFile);
    		CloseHandle(hInputFileMap);
    		CloseHandle(hInputFile);
    		return(FALSE);
    	}
    
    	//used to create a handle to the output file mapping
    	hOutputFileMap = CreateFileMapping(hOutputFile,NULL, PAGE_READWRITE, 0,
    		dwOutputFileSize, NULL);
    	if (hOutputFileMap == NULL)
    	{
    		dwErr = GetLastError();
    		cout<<"Error occured.  The current error number is ";
    		cin>>dwErr;
    		cout<<".";
    		cout<<endl;
    		cout<<"The output file mapping could not be opened due to error.";
    		cout<<endl;
    		cout<<endl;
    		UnmapViewOfFile(pvInputFile);
    		CloseHandle(hOutputFile);
    		CloseHandle(hInputFileMap);
    		CloseHandle(hInputFile);
    		return(FALSE);
    	}
    
    	//usd to map a view of the output file
    	pvOutputFile = MapViewOfFile(hOutputFileMap, FILE_MAP_WRITE, 0, 0, 0);
    	if (pvOutputFile == NULL)
    	{
    		dwErr = GetLastError();
    		cout<<"Error occured.  The current error number is ";
    		cin>>dwErr;
    		cout<<".";
    		cout<<endl;
    		cout<<"The error has caused the map view to be unavailable.";
    		cout<<endl;
    		cout<<endl;
    		UnmapViewOfFile(pvInputFile);
    		CloseHandle(hOutputFileMap);
    		CloseHandle(hOutputFile);
    		CloseHandle(hInputFileMap);
    		CloseHandle(hInputFile);
    		return(FALSE);
    	}
    
    	PSTR pchASCII = (PSTR) pvOutputFile;
    
    	//is the word a palindrome?
    	bool palDrome(char* S)
    	{
    		Stack S(strlen(c) * sizeof(char));
    		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;
    	}
    }
    Code Tags added by Kermi3
    Last edited by milfhunter_04; 09-20-2004 at 07:37 PM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    7
    sorry...i should have read "code tag" thread before i posted this. can someone help me even though i didn't do the code tag?

  3. #3
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    dude, CODE TAGS!! and isn't this the THIRD thread you made about this topic??

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  4. #4
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    >>sorry...i should have read "code tag" thread before i posted this. can someone help me even though i didn't do the code tag?<<

    you could edit you posts...press the "edit" button in the lower tight (right ) corner of your original post.
    Last edited by axon; 09-20-2004 at 07:41 PM.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Sounds like you have your opening and closing braces mixed up somewhere. Also, you have a bool variable called palDrome and another function also called palDrome. => errors.

    **EDIT**
    >>in the lower tight corner of your original post
    *giggle*
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #6
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Code:
    	bool palDrome(char* S)
    This needs to be *outside* of the main function. You either need to put it below the main function and prototype it above, or place the function above the main function. Either way, you need to take it out of the main function and then call it from the main function.

    Also, the error is saying that you already have a variable called palDrome, so change the variable name. *shakes fist*

    Quote Originally Posted by Quzah
    Don't you just love posts that don't say anything at all? Just throw a bunch of code up there, no questions, no description, nothing, and expect you to fix it...

    Quzah.

  7. #7
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    you havent implemented the constructor anywhere.....

  8. #8
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    I have running it , very a lot of error:
    for (int i = 0; x < strlen(c); i++) S.Push(c[i]);
    x not defined
    for (int i = 0; i < strlen(c); i++) S.Push(c[i]);
    request for member `Push' in `S', which is of non-aggregate type `char*'
    while (!S.StackIsEmpty())
    request for member `StackIsEmpty' in `S ', which is of non-aggregate type `char*'

  9. #9
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >> char* S)
    >> {
    >> Stack S(strlen(c) * sizeof(char));



    You named both the char and stack "S"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Yet another clear screen thread :D
    By kermit in forum Linux Programming
    Replies: 2
    Last Post: 11-20-2003, 05:14 AM
  3. Using a button to clear a list box!
    By Unregistered in forum C++ Programming
    Replies: 13
    Last Post: 08-23-2002, 07:44 PM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM