Thread: Palindrome program help please

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

    Palindrome program help please

    Code:
    #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()
    {
    	//Declare variables
    	HANDLE hInputFile;
    	HANDLE hOutputFile;
    	HANDLE hInputFileMap;
    	HANDLE hOutputFileMap;
    	PVOID pvInputFile;
    	PVOID pvOutputFile;
    	DWORD dwInputFileSize = 0;
    	DWORD dwOutputFileSize = 0;
    	DWORD dwErr;
    	char inputFileName [255];
    	char outputFileName[255];
    	char cDrome[10];
    	int iDrome;
    	bool IsDrome;
    	int i;
    
    	cout<<"Enter origin path and file name: ";
    	cin>>inputFileName;
    	cout<<endl<<endl;
    	cout<<"Enter destination path and file name: ";
    	cin>>outputFileName;
    	cout<<endl;
    
    	//create handle for input file
    	hInputFile = CreateFile(inputFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
    		FILE_ATTRIBUTE_NORMAL, NULL);
    	if (hInputFile == INVALID_HANDLE_VALUE)
    	{
    		dwErr = GetLastError();
    		cout<<"Error number: ";
    		cin>>dwErr;
    		cout<<endl;
    		cout<<"Input file could not be opened.";
    		cout<<endl;
    		cout<<endl;
    		return(FALSE);
    	}
    
    	//create handle for input file mapping
    	hInputFileMap = CreateFileMapping(hInputFile, NULL, PAGE_READONLY, 0, 0, NULL);
    	if (hInputFileMap == NULL)
    	{
    		dwErr = GetLastError();
    		cout<<"Error number: ";
    		cin>>dwErr;
    		cout<<endl;
    		CloseHandle(hInputFile);
    		return(FALSE);
    	}
    
    	//create mapped view of the input file
    	pvInputFile = MapViewOfFile(hInputFileMap, FILE_MAP_READ, 0, 0, 0);
    	if (pvInputFile == NULL)
    	{
    		dwErr = GetLastError();
    		cout<<"Error number: ";
    		cin>>dwErr;
    		cout<<endl;
    		cout<<"Could not map view of the input file";
    		cout<<endl;
    		CloseHandle(hInputFileMap);
    		CloseHandle(hInputFile);
    		return (FALSE);
    	}
    
    	//determine size of the input file and compute appropriate size for output
    	dwInputFileSize = GetFileSize(hInputFile, NULL);
    
    	//set string pointer to the first address of the input file
    	PSTR pchANSI = (PSTR) pvInputFile;
    
    	//determine the exact size needed for the output file
    	for (i = 0; i < (int)dwInputFileSize; i++)
    	{
    		iDrome = (int)pchANSI[i];
    		itoa(iDrome, cDrome, 10);
    		dwOutputFileSize = dwOutputFileSize + strlen(cDrome) + 1;
    	}
    
    	//subtract one fm the size to eliminate the last space
    	dwOutputFileSize = dwOutputFileSize - 1;
    
    	//create handle to the output file
    	hOutputFile = CreateFile(hOutputFilename, GENERIC_WRITE | GENERIC_READ, 0, NULL,
    		CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
    	if (hOutputFile == INVALID_HANDLE_VALUE)
    	{
    		dwErr = GetLastError();
    		cout<<"Error number: ";
    		cin>>dwErr;
    		cout<<endl;
    		cout<<"Output file could not be created.";
    		cout<<endl;
    		cout<<endl;
    		UnmapViewOfFile(pvInputFile);
    		CloseHandle(hInputFileMap);
    		CloseHandle(hInputFile);
    		return(FALSE);
    	}
    
    	//create handle to the output file mapping
    	hOutputFileMap = CreateFileMapping(hOutputFilename,NULL, PAGE_READWRITE, 0,
    		dwOutputFileSize, NULL);
    	if (hOutputFileMap == NULL)
    	{
    		dwErr = GetLastError();
    		cout<<"Error number: ";
    		cin>>dwErr;
    		cout<<endl;
    		cout<<"Output file map could not be opened.";
    		cout<<endl;
    		cout<<endl;
    		UnmapViewOfFile(pvInputFile);
    		CloseHandle(hOutputFile);
    		CloseHandle(hInputFileMap);
    		CloseHandle(hInputFile);
    		return(FALSE);
    	}
    
    	//map view of the output file
    	pvOutputFile = MapViewOfFile(hOutputFileMap, FILE_MAP_WRITE, 0, 0, 0);
    	if (pvOutputFile == NULL)
    	{
    		dwErr = GetLastError();
    		cout<<"Error number: ";
    		cin>>dwErr;
    		cout<<endl;
    		cout<<"Could not map view of the output file.";
    		cout<<endl;
    		cout<<endl;
    		UnmapViewOfFile(pvInputFile);
    		CloseHandle(hOutputFileMap);
    		CloseHandle(hOutputFile);
    		CloseHandle(hInputFileMap);
    		CloseHandle(hInputFile);
    		return(FALSE);
    	}
    
    	//set string pointer to the first address of the output file
    	PSTR pchASCII = (PSTR) pvOutputFile;
    
    	//determine if word is a palindrome
    	bool IsDrome(char* c)
    	{
    		Stack S;
    		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;
    	}
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    29
    bcc32 -g100 -j25 -O2 -k- -vi -tWC -c -IC:\CBuilderX\include -oC:\CBuilderX\samples\welcome\windows\Release_Buil d\File1.obj File1.cpp
    Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
    File1.cpp:
    "File1.cpp": E2111 Type 'Stack' may not be defined here at line 25
    "File1.cpp": E2451 Undefined symbol 'inputFilename' in function main() at line 76
    "File1.cpp": E2451 Undefined symbol 'hOutputFilename' in function main() at line 135
    "File1.cpp": E2238 Multiple declaration for 'IsDrome' in function main() at line 195
    "File1.cpp": E2344 Earlier declaration of 'IsDrome' in function main() at line 65
    "File1.cpp": E2141 Declaration syntax error in function main() at line 195
    "File1.cpp": E2139 Declaration missing ; in function main() at line 203
    "File1.cpp": W8004 'pchASCII' is assigned a value that is never used in function main() at line 203
    "File1.cpp": E2190 Unexpected } at line 203
    *** 8 errors in Compile ***
    BCC32 exited with error code: 1
    Build cancelled due to errors

  3. #3
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    can you highlight the lines (color them red or something and comment out) where the errors occur. Some look pretty trivial.

    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
    dude, why the hell did you create a new thread?? http://cboard.cprogramming.com/showthread.php?t=56934

    some entropy with that sink? entropysink.com

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

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    change:
    //contructor
    Stack();
    to:
    //contructor
    Stack::Stack() {}

    add
    //constructor
    Stack::Stack(int size) {
    // fill in details here
    }

    change:
    bool IsDrome(char* c)
    {
    Stack S;

    to:
    bool IsDrome(char* c)
    {
    Stack S(strlen(c) * sizeof(char));


    that should get you started.

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Just thought I'd point out:
    Code:
    #include <iostream>
    #include <string>   //Was string.h
    #include <windows.h>
    #include <cstdio>  //Was stdio.h
    Just Google It. √

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

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  8. #8
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    This is the third post on this topic. Please direct all further comments, questions etc to the most recent post located, here.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. Palindrome Program using Memory mapping
    By rrsanch in forum C++ Programming
    Replies: 1
    Last Post: 09-24-2004, 11:49 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM