Thread: Message in Borland C++

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    5

    Message in Borland C++

    Hi, I'm using Borland Turbo C++ 4.5. Hope you all can help me.

    I received a compile error message saying that the array size is too large in function main(). Can anyone help me to solve this problem?

    I'm using the array of object which contain about 80 objects. Is this too large? Please advise.

    Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <string.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <conio.h>
    #include <ctype.h>
    
    #define tableSize 80
    #define textSize 1000
    
    class Secret
    {
    	int length;
    	char actual;
    	char cipher;
    	char text[textSize];
    	char temp[textSize];
    
    public:
    	Secret(){};
    	Secret(char a, char c){actual=a; cipher=c;}
    	~Secret(){}
    
    	int menu();
    	void encryptMSG(Secret s[]);
    };
    
    
    void Secret::encryptMSG(Secret s[])
    {
    	char filename[15], ans;
    	float count=0, time=0.0;
    
    	system("cls");
    
    	//Prompt to enter message for encryption
    	cout << "\n";
    	cout << "\tEncrypt Message" << endl;;
    	cout << "\t---------------" << endl;
    	cout << "\n\tEnter Message:" << endl;
    	cout << "\n\t";
    	cin.ignore();
    	cin.getline(text, textSize);
    	
    	length=strlen(text);
    
    	//Encryption process start
    	for (int x=0; x<length; x++)
    	{
    		for (int y=0; y<tableSize; y++)
    		{
    			if (text[x]==s[y].actual)
    			{
    				temp[x]=s[y].cipher;
    				count++;
    			}
    		}
    	}
    
    	//Display encrypted message
    	cout << "\n\n";
    	cout << "\n\tEncrypted Message:" << endl;
    	cout << "\n\t";
    
    	for (int z=0; z<length; z++)
    	{
    		cout << temp[z];
    	}
    
    	time=count/10000;
    
    	cout << "\n\n\n\n";
    	cout << "\tTime used for encryption: " << time << " seconds" << endl << endl;
    
    	cout << endl << endl;
    	cout << "\tSave the encrypted message into a file? [Y/N] ";
    	cin >> ans;
    
    	//Save the encrypted message to a file
    	if (ans=='Y'|| ans=='y')
    	{
    		cout << endl;
    		cout << "\tEnter file name [end with .txt]: ";
    		cin >> filename;
    
    		ofstream ofile(filename);
    
    		for (int z=0; z<length; z++)
    		{
    			ofile << temp[z];
    		}
    		ofile.close();
    	}
    }
    
    
    int Secret::menu()
    {
    	int choice;
    
    	cout << "\n\n";
    	cout << "\t---------" << endl;
    	cout << "\tMain Menu" << endl;
    	cout << "\t---------" << endl;
    	cout << "\n";
    	cout << "\t1. Encrypt Message" << endl;
    	cout << "\t2. Exit" << endl;
    	cout <<"\n\tYour Choice: ";
    	cin >> choice;
    
    	return choice;
    }
    
    
    void main()
    {
    	int choice;
    
    	Secret sc[tableSize]={
    		Secret('A','z'), Secret('B','a'), Secret('C','q'), Secret('D','w'), Secret('E','s'),
    		Secret('F','x'), Secret('G','c'), Secret('H','d'), Secret('I','e'), Secret('J','r'),	//10
    		Secret('K','f'), Secret('L','v'), Secret('M','b'), Secret('N','g'), Secret('O','t'),
    		Secret('P','y'), Secret('Q','h'), Secret('R','n'), Secret('S','m'), Secret('T','j'),
    		Secret('U','u'), Secret('V','i'), Secret('W','k'), Secret('X','l'), Secret('Y','o'),
    		Secret('Z','p'), Secret('a','1'), Secret('b','!'), Secret('c','@'), Secret('d','2'),	//30
    		Secret('e','#'), Secret('f','3'), Secret('g','$'), Secret('h','4'), Secret('i','%'),
    		Secret('j','5'), Secret('k','^'), Secret('l','6'), Secret('m','&'), Secret('n','7'),
    		Secret('o','*'), Secret('p','8'), Secret('q','9'), Secret('r','0'), Secret('s','/'),
    		Secret('t','?'), Secret('u','.'), Secret('v',','), Secret('w','+'), Secret('x','-'),	//50
    		Secret('y','='), Secret('z','_'), Secret('+','Y'), Secret('-','Q'), Secret('*','A'),
    		Secret('/','Z'), Secret(' ','X'), Secret('!','S'), Secret('@','W'), Secret('#','E'),
    		Secret('$','D'), Secret('%','C'), Secret('^','V'), Secret('&','F'), Secret('_','R'),	
    		Secret('=','T'), Secret('?','G'), Secret('.','B'), Secret(',','N'), Secret('|','H'),	//70
    		Secret('1','~'), Secret('2',':'), Secret('3','<'), Secret('4','>'), Secret('5','{'),
    		Secret('6','`'), Secret('7','}'), Secret('8','['), Secret('9',']'), Secret('0','U')		//80
    	};
    
    	Secret sd;
    
    	do
    	{
    		choice=sd.menu();
    		
    		switch(choice)
    		{
    			case 1: sd.encryptMSG(sc);
    					system("cls");
    					break;
    
    			case 2: cout << "\n\t";
    					exit(2);
    
    			default: cout << "\n\tInvalid Choice!" << endl;
    					 break;
    		}
    	} while (choice>0 && choice<2);
    }
    Last edited by elquex; 03-26-2003 at 03:02 AM.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    It would seem to be specific to your set up, it compiles and runs fine with VC. No help to you of course, but at least you know it is not a coding error!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User Dev's Avatar
    Join Date
    Mar 2003
    Posts
    59
    Is Turbo C++ 4.5 for Dos or Windows ?

    I think the problem would be with the memory model in which you are compiling your program.

    Try changing the memory model in Options -> Configuration or wherever your compiler's configuration dialog is.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    5
    Thank you guys, I will try that... thanks a lot.

    Dev, I'm using the Turbo C++ 4.5 windows version and I can't find the configuration under the option... May be is different version

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07:38 PM
  2. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM