Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Tricky C programming problem


  • Please log in to reply

#1
puritan

puritan

    Member

  • Member
  • PipPip
  • 10 posts
Hi!

I am writing a program for a robot control GUI, and I want to read from the keybord and be able to drive the robot around.
I thought it should be simple but it isn't, atleast not for me.... :tazz:

I wrote this:

char c;
while(1)
{
c = getchar();
switch © {
Choices regarding drive forward and....

}

My problem is this...
getchar() doesnt only read from the keystrokes, it buffers them and even with my altered unbuffered one it still needs the endofline to execute, I can drive the robot but in a stupid ineffective way.
So is there any fuction that listens to the keystrokes and doesnt echo them?

I am trying to do this with gcc and under Slackware.

Best regrads
Puritan
  • 0

Advertisements


#2
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 875 posts
hi puritan,

let's see if you can use kbhit() - which will let the program respond to single keystrokes

add this line near the top of your code
#include <conio>

if the compiler complains try
  #include "conio.h"

if one of the above is ok try

  while(1) {
	if( kbhit() ) {
	  c = getch();
	  break;
	}
  }

then modify it to suit your needs

bdlt
  • 0

#3
puritan

puritan

    Member

  • Topic Starter
  • Member
  • PipPip
  • 10 posts
Hi!

Thx for the fast answer, the problem is that conio.h isn't supported, but I maight add that I am not a Unix-guru, though not stupid... :tazz:
The problem is that any function uses blocking and under Windows it works fine cause Windows Operating system doesnt allow blocking but Slackware do, so how do I modify or get past this problem, there are 2 problems then

1. It buffers the data
2. The function getchar() uses blocking

Best regards
Puritan
  • 0

#4
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 875 posts
here are some links you might try. these were found using a google search on kbhit, c++, unix.

http://www.tek-tips....d=939697&page=7
http://www.codecomme...5-6-525153.html
http://apps.carleton...ource/keyb_int/
http://www.thp.uni-d...&OFFSET=2127176
  • 0

#5
puritan

puritan

    Member

  • Topic Starter
  • Member
  • PipPip
  • 10 posts
Problem Solved, found a solution, you cann close this thread, thx for the help!

Best regards
Puritan
  • 0

#6
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 875 posts
hi Puritan,

congrats on finding a solution. can you post your solution so that others may benefit from it?

bdlt
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP