![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Manage Ogg audio streams with OGMtools | iBot | UNIX and Linux RSS News | 0 | 06-03-2008 04:40 AM |
| WARNING: No Memory for Streams (NSTRPAGES) | Steve_93630 | SCO | 1 | 01-03-2006 12:43 PM |
| Help capturing and reformatting buffered and unbuffered output | vikingshelmut | Shell Programming and Scripting | 0 | 09-27-2005 02:27 PM |
| Transparent ioctls Streams calls | S.P.Prasad | UNIX for Advanced & Expert Users | 2 | 05-31-2002 12:49 AM |
| STREAMS | alwayslearningunix | UNIX for Dummies Questions & Answers | 1 | 04-10-2001 05:11 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
unbuffered streams.
#include "../ourhdr.h"
int main(void) { int c; char *buf; setvbuf(stdin,buf,_IONBF,10); setvbuf(stdout,buf,_IONBF,10); while((c=getc(stdin)) != EOF) { if(putc(c,stdout) == EOF) err_sys("output error"); } if (ferror(stdin)) err_sys("input error"); exit(0); } for the above program i expected following output. $> ./a.out hh (user input is in black colour and output is indicated in blue colour) but the output is coming after pressing return key h<return-key> h see in the above code i made stdin and stdout as unbuffered streams.. so can anyone explain why the output is coming after pressing return key.. |
|
||||
|
You have to set the tty to canonical ---
This reads one key at a time without requiring the <return> Code:
int getch(void) {
int c=0;
struct termios org_opts, new_opts;
int res=0;
//----- store old settings -----------
res=tcgetattr(STDIN_FILENO, &org_opts);
assert(res==0);
//---- set new terminal parms --------
memcpy(&new_opts, &org_opts, sizeof(new_opts));
new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL);
tcsetattr(STDIN_FILENO, TCSANOW, &new_opts);
c=getchar();
//------ restore old settings ---------
res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts);
assert(res==0);
return(c);
}
|
|
||||
|
I too was suffering from this problem, and I hit another snag. When I tried this sample code it still wouldn't work form me, until I entered a total of 4 characters or hit return 3 times after having entered my first desired character.
After a lot of digging, I found that there is a minimum value setting in the termios structure that dictates the minimum number of characters that must be read before it passes the data to you. The default is suppose to be 1, but in my case it was set to 4. How? I don't know, but it is. I resolved this problem by adding the following line: Code:
new_opts.c_cc[VMIN]=1; Code:
tcsetattr(STDIN_FILENO, TCSANOW, &new_opts); I just wanted to point out that this was 99% perfect for me, and this 1% was all that I lacked. This may help someone else too. -=John |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|