1,105,556 Community Members

HELP! How to Move the cursor in turbo c

Member Avatar
cutterpillow20
Newbie Poster
9 posts since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Good day, i'm new in C.. can you give me some idea in how to program a moving cursor in the output screen and highlight the text... because i will use this in my coming final project in school.. we will make a system in TURBO C..

hoping for reply... THANK YOU!

Member Avatar
deceptikon
Eternally Awesome
4,690 posts since Jan 2012
Reputation Points: 1,341 [?]
Q&As Helped to Solve: 688 [?]
Skill Endorsements: 104 [?]
Administrator
Featured
 
0
 

In Turbo C you can use gotoxy(), and for the highlighting you'd probably use textcolor(). Read the documentation for further details about those two functions.


inb4 don't use Turbo C.

Member Avatar
cutterpillow20
Newbie Poster
9 posts since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

In Turbo C you can use gotoxy(), and for the highlighting you'd probably use textcolor(). Read the documentation for further details about those two functions.


inb4 don't use Turbo C.

Thank You for tha Information sir... but my problem that i can move/manipulate the cursor left, right, down, up in the output screen.

Hope you can help me...

Member Avatar
deceptikon
Eternally Awesome
4,690 posts since Jan 2012
Reputation Points: 1,341 [?]
Q&As Helped to Solve: 688 [?]
Skill Endorsements: 104 [?]
Administrator
Featured
 
0
 

but my problem that i can move/manipulate the cursor left, right, down, up in the output screen.

I don't understand.

Member Avatar
Ancient Dragon
Achieved Level 70
27,637 posts since Aug 2005
Reputation Points: 5,232 [?]
Q&As Helped to Solve: 3,037 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

Thank You for tha Information sir... but my problem that i can move/manipulate the cursor left, right, down, up in the output screen.

Hope you can help me...

He already told you how -- call gotoxy().

Member Avatar
student_learner
Newbie Poster
16 posts since Nov 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hope this help:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
long k;
clrscr();
for(i=0;i<=300;i++)
{
clrscr();
for(j=0;j<=i;j++)
{
printf(" ");
  }
//printf("abc");
for(k=1;k<=900000;k++);//increasing this value will slow down the cursor speed.
   }              
getch();
}
Member Avatar
Ancient Dragon
Achieved Level 70
27,637 posts since Aug 2005
Reputation Points: 5,232 [?]
Q&As Helped to Solve: 3,037 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

>>for(k=1;k<=900000;k++);//increasing this value will slow down the cursor speed.

Horrible waste of CPU time! That is dependent on CPU speed. In Turbo C call its delay() function.

Member Avatar
cutterpillow20
Newbie Poster
9 posts since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Deciptikon, Ancient Dragon, and student learner... thank you for the reply. When i was surfing in the net i come with this site "http://ascii-table.com/ansi-escape-sequences.php".. this is what i mean.. can you teach me how to do that "ANSI escape" or give some sample program...

Thank You so much...

Member Avatar
deceptikon
Eternally Awesome
4,690 posts since Jan 2012
Reputation Points: 1,341 [?]
Q&As Helped to Solve: 688 [?]
Skill Endorsements: 104 [?]
Administrator
Featured
 
0
 

You *might* be able to use ANSI escape sequences by loading ANSI.SYS. But it's a really bad solution to the problem when Turbo C already supports such library functions as gotoxy() and textcolor().

Member Avatar
zero9159743726
Newbie Poster
2 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 
#include<stdio.h>
#include<conio.h>

#define d1 gotoxy(1,1);textcolor(RED);cprintf(" P");textcolor(7);cprintf("relim       ");
#define d2 gotoxy(1,6);textcolor(RED);cprintf(" M");textcolor(7);cprintf("idterm      ");
#define d3 gotoxy(1,12);textcolor(RED);cprintf(" S");textcolor(7);cprintf("emi finals  ");
#define d4 gotoxy(1,18);textcolor(RED);cprintf(" F");textcolor(7);cprintf("inals       ");
#define keys gotoxy(1,24);printf("Esc = exit\tArrow keys = up/down/left/right");
#define d clrscr(); keys d1 d2 d3 d4

int c,cx=0,cy=0,i1,i2,i3,i4,i5,i6,i7; /*some variables will be use --in progress -*/ 
char c1,c2,c3,c4,c5,c6,c7,c8;
float f1,f2;

void updown()
  {
  switch(c)
    {
    case  72 : cy = cy - 1;
	       break;
    case  80 : cy = cy + 1;
	       break;
    default  : printf("");
    }
  }



void b2()
  {
  switch(cx)
    {
    case  1 : gotoxy(20,1);printf("PRELIM\n");
	      gotoxy(20,2);printf("PROGRAM 1\n");
	      gotoxy(20,3);printf("PROGRAM 2\n");
	      gotoxy(20,4);printf("PROGRAM 3\n");
	      break;
    case  2 : gotoxy(20,1);printf("MIDTERM\n");
	      gotoxy(20,2);printf("PROGRAM 1\n");
	      gotoxy(20,3);printf("PROGRAM 2\n");
	      gotoxy(20,4);printf("PROGRAM 3\n");
	      break;
    case  3 : gotoxy(20,1);printf("SEMI FINALS\n");
	      gotoxy(20,2);printf("PROGRAM 1\n");
	      gotoxy(20,3);printf("PROGRAM 2\n");
	      gotoxy(20,4);printf("PROGRAM 3\n");
	      break;
    case  4 : gotoxy(20,1);printf("FINALS\n");
	      gotoxy(20,2);printf("PROGRAM 1\n");
	      gotoxy(20,3);printf("PROGRAM 2\n");
	      gotoxy(20,4);printf("PROGRAM 3\n");
	      break;
    default : printf("");
    }
  }

void leftright()
  {
  if(c==77 || c==75)
    {
    if(c==77)

      if(cy==1)
      cx=1;
      else if(cy==2)
      cx=2;
      else if(cy==3)
      cx=3;
      else if(cy==4)
      cx=4;

    else if(c==75)
      cx=0;
    }
  else
    cx=0;
  }



void b1()
  {
  if(cy>=5)
    cy=1;
  else if(cy<=-1)
    cy=4;
  switch(cy)
    {
    case  1 : d textbackground(9); d1 textbackground(BLACK); d2 d3 d4
	      break;
    case  2 : d textbackground(9); d2 textbackground(BLACK); d3 d4
	      break;
    case  3 : d textbackground(9); d3 textbackground(BLACK); d4
	      break;
    case  4 : d textbackground(9); d4 textbackground(BLACK);
	      break;
    default : printf("");
    }
    leftright();
    b2();
  }





main()
  {
  d
  do
    {
    c = getch();
    d
    updown();
    b1();
    b2();
    }
  while(c!=0x1b);
  }

TESTING mo brad .. sensya na magulo yung gawa ko hehe 1st day ko plang ginawa e :))
this is our individual project for final
**note** my program is still in progress

pankaj15389
Newbie Poster
1 post since Jul 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
-1
 

to move cursor you need to ch=getch();
in loop;
then you have to just match ch=='P' or 'K','H','M'
left arrow = K
right arrow = M
up arrow = H
down arrow = P
now use gotoxy(x,y)
x++,y
x--,y
x,y++
x,y--

yoon eun suh
Newbie Poster
1 post since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

hi cutterpillow20 now I have the same problem as you had. could you get any awnser if yes then help me too. :) thanks

Member Avatar
Ancient Dragon
Achieved Level 70
27,637 posts since Aug 2005
Reputation Points: 5,232 [?]
Q&As Helped to Solve: 3,037 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

Didn't you read the rest of this thread???? No one can help you if you don't know how to read.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article