Jump to content
  • Advertisement
Sign in to follow this  
BaldPython

Code problem

This topic is 4727 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Please Please Please Help me, gotoxy() along with the weird working of backspace is driving me crazy ... the comments are given with the stepts where I am falling ... BTW ... this is the code for a notepad ... [soruce="cpp"] #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 = 34 , ALT_C = 47 , F4 = 62 , }; enum SCREENSTATS{ MAXX = 80 , MAXY = 24 , AREAX = MAXX-1 , AREAY = MAXY-1 , MIDX = MAXX/2 , MIDY = MAXY/2 , }; //************************************************************************ // End of Constant Block //************************************************************************ //************************************************************************ // 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); //************************************************************************ // End of Function ProtoType Block //************************************************************************ //************************************************************************ // main() Program //************************************************************************ int main() { //*****************************/ // VARAIABLE block //*****************************/ 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=1; gotoxy(x,y); // Here's problem-1: the cursor isnt returning as it supposed to the pointed location while( (key=getch()) != 27 ) if( key == 0 ) switch(getch()) // Incomplete Part ... Skip This whole Block { case L_ARROW: //if(x>0) gotoxy(--x,y); break; case R_ARROW: //if(x<MAXX) gotoxy(++x,y); break; case U_ARROW: //if(y>0) gotoxy(x,--y); break; case D_ARROW: gotoxy(x,++y); break; case ALT_S: printf(msgs[6]); break; case F4: exit(0); } else { if(key == 0x0a || key == 0x0d) cputs("\n"); if(key == 0x08) // Backspace --- BIGGEST PROBLEM FOR ME, NOT SOLVED YET { gotoxy(--(x=wherex()),(y=wherey())); key = 0; } cprintf("%c",key); 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(BLACK); textbackground(WHITE); cprintf(msgs); } else if( c == pos2 ) { textcolor(BLACK); textbackground(WHITE); cprintf(msgs2); } else if( c == pos3 ) { textcolor(BLACK); textbackground(WHITE); cprintf(msgs3); } else { y=wherey(); if(y != 2) cputs(" "); else break; } } } [/source] [Edited by - BaldPython on June 15, 2005 4:40:55 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
(source lang="cpp")
(/source)

:) () = []

Share this post


Link to post
Share on other sites
Make your own gotoxy

Here's the code

#include <windows.h>

void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}


I remember using this, it works great.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!