LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-23-2005, 10:00 AM   #1
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Rep: Reputation: 30
reading one character


i want to read one character and the echo it on screen. i want to do this only using standard c libraries on linux (something like getch() from conio.h) How can I do that?
I tryed:

#include<stdio.h>

int main()
{
int c;
c=getc(stdin);
printf("%c\n",c);
return 0;
}


it reads a string and prints only the first character. how can i make it stop afer reading the first character!
 
Old 12-23-2005, 01:16 PM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Your code reads one character from a stream, then prints that character and exits. The rest of the input stream is discarded after the program terminates and the STDIN file descriptor is closed by the OS.
 
Old 12-23-2005, 01:27 PM   #3
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Original Poster
Rep: Reputation: 30
yes i know... but i want after the i get the first character to print it imediately not wait until i press [ENTER]!
 
Old 12-24-2005, 06:11 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
See for example these threads:
http://www.linuxquestions.org/questi...ad.php?t=34027
http://www.linuxquestions.org/questi...d.php?t=134966
 
Old 12-24-2005, 06:17 AM   #5
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Original Poster
Rep: Reputation: 30
http://www.linuxquestions.org/questi...d.php?t=134966
this one really helps!

Thank you very much!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Character Map Jongi Linux - General 1 07-06-2005 06:14 PM
Problem with reading and printing a character hubabuba Programming 3 02-28-2005 02:41 PM
Character replacement SeT Linux - General 1 11-18-2004 12:21 PM
^M character david_wliu Linux - General 6 03-16-2003 11:16 PM
Character filtering see2bee Programming 2 02-25-2003 08:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration