![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Mar 2005
Posts: 40
Rep Power: 0
![]() |
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 ... |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|