Showing posts with label move your text on console screen. Show all posts
Showing posts with label move your text on console screen. Show all posts

Monday, 19 May 2014

Moving text on console screen

#include<conio.h>
#include<iostream>
#include<windows.h>
#include<color.h>
#include<stdio.h>
#include<string.h>
using namespace std;
void gotoxy (int x, int y)
{
    COORD coord;
    coord.X = x; coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

void l_to_r(char *s)
{
for(int i=0;i<35;i++)
{
system("cls");
gotoxy(i,10);
puts(s);
Sleep(80);
}
}

void r_to_l(char *s)
{
for(int i=80-strlen(s);i>35;i--)
{
system("cls");
gotoxy(i,10);
puts(s);
Sleep(80);
}
}

void t_to_d(char *s)
{
for(int i=0;i<18;i++)
{
system("cls");
gotoxy(35,i);
puts(s);
Sleep(80);
}
}
void b_to_u(char *s)
{
for(int i=20;i>10;i--)
{
system("cls");
gotoxy(35,i);
puts(s);
Sleep(80);
}
}
int main()
{
char s1[25];
int ch=1;
cout<<"Enter text :";
    gets(s1);
    cout<<"\n choose your option :\n\n1) Left to Rtigh  \n2)Right to Left\n3)Top to Down \n4) Bottom to Up \n";
    cin>>ch;
switch(ch)
{
case 1:
          l_to_r(s1);
break;
case 2:
r_to_l(s1);
break;
case 3:
t_to_d(s1);
break;
case 4:
b_to_u(s1);
break;
default: {
cout<<"\nPlease enter valid option !";
}

}
getch();
return 0;
}