Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 05-10-2008, 08:00 PM   #1 (permalink)
Wise Old Owl
 
speedyguy's Avatar
 
Join Date: Aug 2004
Location: Bangalore/Jamshedpur
Posts: 1,173
Default C/C++ Querry: Random input


m a noob...ok a bit better than a noob....

so m desgining an animation program whr i need a halt an on going animation..

so my querry is - which command do i use to randomly get an input while a process is active...
for eg. an animation is goin on in an infinite loop....i want user 2 break it on pressing "Q" key....so how do code it???

2ndly....for animation shud i use clrscr() for motion or any other command?

thanks...

Enjoy~!
__________________
No Pain...No Gain
speedyguy is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 05-10-2008, 08:04 PM   #2 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: C/C++ Querry: Random input

Create a seperate thread for animation ?
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 06-10-2008, 01:23 AM   #3 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Default Re: C/C++ Querry: Random input

As for randomization :
Code:
randomize(); //Initialize Engine
n=rand(); //n integer takes from 0 to highest possible number
Or select within range 10 - 90
Code:
n=rand()%81+10;

For input and break you can use kbhit() syntax

Code:
while(!kbhit())
{
body
}
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Old 06-10-2008, 01:38 AM   #4 (permalink)
Wise Old Owl
 
harryneopotter's Avatar
 
Join Date: Feb 2007
Posts: 1,009
Default Re: C/C++ Querry: Random input

exactly wat type of animation r u looking for ?
__________________
Wats the Favourite Mathematical Function of DIGIT FORUM ????

Its "A SINE WAVE" constant

Y ??

They Both keep going "UP AND DOWN, UP AND DOWN............" !!!!!!!!
harryneopotter is offline  
Old 09-10-2008, 08:45 PM   #5 (permalink)
Wise Old Owl
 
speedyguy's Avatar
 
Join Date: Aug 2004
Location: Bangalore/Jamshedpur
Posts: 1,173
Default Re: C/C++ Querry: Random input

just a loop....for ex creating circle of increasing radius wit the loop value....n wanna break in between wen d user wants to......that kind....

@anantkhaitan: i think this one is wat i need...
while(!kbhit())
{
body
}

but thats jus for a random key hit....suppose i want a specific key to break that loop?

thanks

Enjoy~!

ps: i tried kbhit().....its working.....can i use it wit parameters?

Enjoy~!
__________________
No Pain...No Gain

Last edited by speedyguy; 09-10-2008 at 08:52 PM. Reason: Automerged Doublepost
speedyguy is offline  
Old 10-10-2008, 12:27 PM   #6 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: C/C++ Querry: Random input

Nope.

int kbhit(void); (Non-ANSI) returns a non-zero integer in case some key is hit and 0 otherwise. Doesn't tell you what key was hit.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 10-10-2008, 04:13 PM   #7 (permalink)
Wise Old Owl
 
speedyguy's Avatar
 
Join Date: Aug 2004
Location: Bangalore/Jamshedpur
Posts: 1,173
Default Re: C/C++ Querry: Random input

ok so any other command for this?

Enjoy~!
__________________
No Pain...No Gain
speedyguy is offline  
Old 10-10-2008, 09:06 PM   #8 (permalink)
Legen-wait for it-dary!
 
dheeraj_kumar's Avatar
 
Join Date: Dec 2004
Location: Chennai
Posts: 2,471
Default Re: C/C++ Querry: Random input

@Qwerty

Isnt the non zero number the keycode of the pressed key?
__________________
If the Start Windows Restart when Windows starts check box is checked Windows Restart will start automatically every time Windows is started. - Actual excerpt from a windows program help file
dheeraj_kumar is offline  
Old 10-10-2008, 10:53 PM   #9 (permalink)
Wise Old Owl
 
harryneopotter's Avatar
 
Join Date: Feb 2007
Posts: 1,009
Default Re: C/C++ Querry: Random input

hey ... u can try this ..

void main()
{char ch;

start:
while (!kbhit())
{ch=getch();
if("Your condition to check which key has been pressed, if its the specific key that u wanted to be pressed to break the loop then ..")
goto next;

else
goto start;

next:
BODY OF THE LOOP;
}

Hope you got it ......
__________________
Wats the Favourite Mathematical Function of DIGIT FORUM ????

Its "A SINE WAVE" constant

Y ??

They Both keep going "UP AND DOWN, UP AND DOWN............" !!!!!!!!
harryneopotter is offline  
Old 11-10-2008, 11:04 AM   #10 (permalink)
Wise Old Owl
 
speedyguy's Avatar
 
Join Date: Aug 2004
Location: Bangalore/Jamshedpur
Posts: 1,173
Default Re: C/C++ Querry: Random input

yup i got it...thanx mate...

Enjoy~!
__________________
No Pain...No Gain
speedyguy is offline  
Old 11-10-2008, 11:10 AM   #11 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: C/C++ Querry: Random input

Quote:
Originally Posted by dheeraj_kumar View Post
@Qwerty

Isnt the non zero number the keycode of the pressed key?
Nope, AFAIK all kbhit does is check if a value exists in the keyboard buffer and several can exist too. So it just returns any non-zero value on success and 0 otherwise. It's just checking for a stroke and thus getch() will get the normal input post the pressed event, when called.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 11-10-2008, 07:31 PM   #12 (permalink)
Legen-wait for it-dary!
 
dheeraj_kumar's Avatar
 
Join Date: Dec 2004
Location: Chennai
Posts: 2,471
Default Re: C/C++ Querry: Random input

@Qwerty

Got it, thanks!
__________________
If the Start Windows Restart when Windows starts check box is checked Windows Restart will start automatically every time Windows is started. - Actual excerpt from a windows program help file
dheeraj_kumar is offline  
Old 11-10-2008, 11:59 PM   #13 (permalink)
Wise Old Owl
 
harryneopotter's Avatar
 
Join Date: Feb 2007
Posts: 1,009
Default Re: C/C++ Querry: Random input

i knew it will work coz it worked in my project too ...

__________________
Wats the Favourite Mathematical Function of DIGIT FORUM ????

Its "A SINE WAVE" constant

Y ??

They Both keep going "UP AND DOWN, UP AND DOWN............" !!!!!!!!
harryneopotter is offline  
Old 19-10-2008, 09:45 PM   #14 (permalink)
Wise Old Owl
 
speedyguy's Avatar
 
Join Date: Aug 2004
Location: Bangalore/Jamshedpur
Posts: 1,173
Default Re: C/C++ Querry: Random input

ok 1 more querry here....refer d foll codes....ofcourse ts not a complete project...tsa work in progress....

"#include<iostream.h>
#include<conio.h>
#include<alloc.h>
#include<graphics.h>

#define CLIP 1

int avg[12][5];

void far setviewport(int,int,int,int,int);
void far getimage(int,int,int,int,void far *buf);
void far putimage(int,int,void far *buf);

void border(int thickness)
{
int i;
cleardevice();
setcolor(4);
for (i=1;i<thickness;i++)
rectangle(20+i,20+i,600+i,450+i);
}

void mainpage()
{
void far *buf;
int style;
border(8);
style=DEFAULT_FONT;
settextstyle(style,HORIZ_DIR,2);
setcolor(5);
outtextxy(75,70,"AUTO-MOBILE FUEL CONSUMPTION");
setcolor(2);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(80,320,"Simulation Project by ABHINAV ARYA");
outtextxy(110,340,"V SEM BCA, Garden City College");
setcolor(12);
style=GOTHIC_FONT;
settextstyle(style,HORIZ_DIR,1);
outtextxy(290,380,"press any key to continue...");
setcolor(6);
rectangle(120,200,450,250);
for (int i=120;i<450;i++)
line(i,200,i,250);
for (i=1;i<30;i++)
{
if (i>20)
setcolor(8);
circle(200,250,i);
circle(370,250,i);
}
setcolor(1);
for (i=190;i<330;i++)
{
line(i,200,i+20,170);
}
for (i=330;i<390;i++)
{
line(i,200,i-20,170);
}
setcolor(6);
line(210,170,370,170);
setcolor(0);
line(190,200,390,200);
line(290,170,290,250);
setcolor(8);
for (i=280;i<310;i++)
line(40,i,70,i);
getimage(40,280,70,310,buf);
setviewport(40,280,600,310,CLIP);
while(!kbhit())
{
for (i=0;i<500;i++)
{
clearviewport();
putimage(i,0,buf,COPY_PUT);
}
}
farfree(buf);
}

int selection()
{
border(4);
setbkcolor(4);
setcolor(9);
settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
outtextxy(80,100,"AUTOMOBILE FUEL CONSUMPTION");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(50,150,"Cubic Capacity Chart:::::");
getch();
return 0;
}

// START OF THE MAIN FUNCTION //
void main()
{
int gd=DETECT,gm;
int avg_ch,avg_f,x;
int avg_dn;
clrscr();
initgraph(&gd,&gm,"");
mainpage();
cleardevice();
avg_ch=selection();
switch(avg_ch)
{
case 1:avg_f=60;
avg_dn=100;
break;
case 2:avg_f=55;
avg_dn=150;
break;
case 3:avg_f=45;
avg_dn=180;
break;
case 4:avg_f=35;
avg_dn=250;
break;
case 5:avg_f=20;
avg_dn=800;
break;
case 6:avg_f=18;
avg_dn=1000;
break;
case 7:avg_f=17;
avg_dn=1200;
break;
case 8:avg_f=15;
avg_dn=1400;
break;
case 9:avg_f=14;
avg_dn=1800;
break;
case 10:avg_f=12;
avg_dn=2000;
break;
case 11:avg_f=10;
avg_dn=2200;
break;
case 12:avg_f=8;
avg_dn=2500;
break;
}
getch();
closegraph();
}"

acc to this...wat happens on o/p screen is mainpage() func executes normally wit a small anim but on pressing a key (ie. call of func selection()) the compiler crashes n returns back 2 window....plz exec this code n see if its same wit u...n if u can help me out wit dis....thrs no compiler error on it.

Enjoy~!
__________________
No Pain...No Gain
speedyguy is offline  
Closed Thread

Bookmarks

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which Input devices r u using? gxsaurav QnA (read only) 15 08-09-2008 03:00 AM
Mask input in Java redhat Programming 7 29-11-2007 10:35 PM
No audio input! Chetan1991 Software Q&A 2 04-02-2007 02:35 PM
17 " lcd with DVI input Ringwraith TVs / Monitors 18 29-09-2005 02:42 PM

 
Latest Threads
- by clinton
- by soumya
- by Sujeet
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 11:14 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2