Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 19th, 2005, 8:42 AM   #1
Planet_EN
Programmer
 
Join Date: Mar 2005
Posts: 40
Rep Power: 0 Planet_EN is an unknown quantity at this point
Notepad Code Problem

#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <fcntl.h>
#include <stdlib.h>


int 	x,y;

//*********************************************************
//                 Constants Block
//*********************************************************
enum xKEYS {
		L_ARROW = 75 ,
		R_ARROW = 77 ,
		U_ARROW = 72 ,
		D_ARROW = 80 ,
		ALT_O   = 24 ,
		ALT_N   = 49 ,
		ALT_S   = 31 ,
		ALT_Q   = 16 ,
		ALT_H   = 35 ,
		ALT_C   = 46 ,
		F4      = 62 ,
		};

enum SCREENSTATS{
			MAXX = 80      ,
			MAXY = 24      ,
			AREAX = MAXX-1 ,
			AREAY = MAXY-1 ,
			MIDX = MAXX/2  ,
			MIDY = MAXY/2  ,
		};





//*********************************************************
//                 Function ProtoTypes
//*********************************************************

int open_file();
int create_new_file();
int _Row(int limit,char msgs[],int pos1,char msgs2[],int pos2,char msgs3[],int pos3);




//*********************************************************
//		           main() Program
//*********************************************************

int main()
{

	// VARAIABLES
	int		key;
	int		c;
	char*	msgs[] = {
				 "Alt + N (NewFile)"
				,"Alt + O (Open)"
				,"Alt + S (Save)"
				,"Alt + H (Help)"
				,"Alt + C (Close)"
				,"Alt + Q (Quit)"
				,"\nDo you want to save the Document"
				,"\nDo you wish to contiue "
				,"\n Y for Yes and N for No"

			 };

	int keysize;

	keysize=(sizeof msgs) / (sizeof msgs[0]);
	x=y=0;

	clrscr();
	textmode(3);

	 gotoxy(0,0);
			_Row(40,msgs[0],4,msgs[1],15,msgs[2],24);

	 gotoxy(MAXX,MAXY);
			_Row(40,msgs[3],4,msgs[4],15,msgs[5],24);

	textcolor(LIGHTGREEN);
	textbackground(BLACK);

	x=0,y=2;
	window(0,2,AREAX,AREAY);
	gotoxy(x,y);
	 /*
		The problem is with the above gotoxy()
		It is not returning to the location (0,1)
		inspite it remains at the last line
	 */

  while( (key=getch()) != 27 )
	if( key == 0 )
		switch(getch())  // Incomplete Part ... Skip This whole Block
		{
			case L_ARROW:
				if( 0 < x && y > 1)
				  gotoxy(--x,y);
				break;
			case R_ARROW:
				if( MAXX > x && y < 1 )
				  gotoxy(++x,y);
				break;
			case U_ARROW:
				if(y>1)
				  gotoxy(x,--y);
				break;
			case D_ARROW:
				gotoxy(x,++y);
				break;
			case ALT_S:
				printf(msgs[6]);
				break;
			case ALT_O:
			case ALT_N:
			case ALT_Q:
			case ALT_H:
			case ALT_C:
			case F4:
				exit(0);
			defealt:
				break;

		}
	else
	{
	   if(key == 0x0a || key == 0x0d)
		   if(x != MAXX && y !=MAXY)

			   putchar('\n');

	   if(key == 0x08)  // Backspace --- BIGGEST PROBLEM FOR ME, NOT SOLVED YET
	   {

			x=wherex();
			y=wherey();
			gotoxy(x,y);
			cprintf("%c", ' ');
			gotoxy(x,y);

		}

	  x=wherex();
	  y=wherey();

	  }

  return EXIT_SUCCESS;
}

//************************************************************************
//			   Function Definations
//************************************************************************

int newfile(char* fname,int key)
{
   FILE* in;
	  if ((in = fopen(fname, "w+")) == NULL)
	  {
		fprintf(stderr, "Cannot create new file.\n");
		return 1;
	  }

}


int _Row(int limit,char msgs[],int pos1,char msgs2[],int pos2,char msgs3[],int pos3)
{
  int c;
		for(c=0; c < limit ;c++)
		{
			textcolor(BLACK);
			textbackground(WHITE);

			if( c == pos1 )
				{
					textcolor(RED);
					textbackground(WHITE);
					cprintf(msgs);
				}
			else if( c == pos2 )
				{
					textcolor(RED);
					textbackground(WHITE);
					cprintf(msgs2);
				}
			else if( c == pos3 )
				{
					textcolor(RED);
					textbackground(WHITE);
					cprintf(msgs3);
				 }
			else
				{
					y=wherey();
					  if(y != 2)
						cputs(" ");
					  else
						break;
				 }
		}
}

the gotoxy() is not returning to its original position ...
Planet_EN is offline   Reply With Quote
Old Jun 19th, 2005, 10:13 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
The sort of functions one finds in conio files are implementation dependent (they're not standard C/C++). You should give some specific information regarding your platform, your OS, your compiler, and the source of your non-portable library stuff.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 19th, 2005, 7:30 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I'm guessing you're using Borland C++ - can you verify this?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:32 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC