LinuxQuestions.org
Help answer threads with 0 replies.
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 10-09-2003, 10:48 PM   #1
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Rep: Reputation: 33
Change buffer delimiter from "\n"


The inbuilt buffer delmiter will be "\n" i.e, only after a "\n" is encountered the input will be accepted by the program...Until then it'll be stored in the buffer . On receiving a carriage return it is sent to the program which requested it....

I want to write a c-program which takes input as they come i.e,
if the user types "a" I must accept it even if he doesn't type "\n"

P.S :- I think ncurses might help .......
 
Old 10-10-2003, 12:35 AM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
ncurses probably would help, but so would modifying the tty canonical mode.

Try these links:
http://www.linuxquestions.org/questi...002/11/4/36402
http://www.linuxquestions.org/questi...002/07/4/24296
 
Old 10-10-2003, 02:54 AM   #3
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Original Poster
Rep: Reputation: 33
Thanx for the help .... It was really wonderful.

Now how do I implement the same using ncurses.

Just out of curiousity.What functions am I supposed to use to do the same ??
 
Old 10-10-2003, 05:36 AM   #4
wuck
Member
 
Registered: Sep 2003
Location: barneveld.nl
Distribution: Slackware
Posts: 170

Rep: Reputation: 30
How about: (FIXME)

Code:
char a;

while ((a = getchar()) != EOF)
 putchar (a);
This is what I use for streaming programs.
 
Old 10-10-2003, 08:08 AM   #5
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Original Poster
Rep: Reputation: 33
Maybe u should read the problem statement again
Using getchar(),

The output will be printed line by line i.e, you enter a line and then a line is printed , then another line is accepted,printed....
This is because the delimiter of internal buffer is "\n" ...

What I want is a character by character print...
 
Old 10-10-2003, 08:50 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Code:
#include <stdio.h>
#include <termios.h>
     
static struct termios stored_settings;
     
void set_keypress(void)
{
     struct termios new_settings;
     
     tcgetattr(0,&stored_settings);
     new_settings = stored_settings;
     new_settings.c_lflag &= (~ICANON);
     new_settings.c_cc[VTIME] = 0;
     new_settings.c_cc[VMIN] = 1;
     tcsetattr(0,TCSANOW,&new_settings);
}
     
void reset_keypress(void)
{
     tcsetattr(0,TCSANOW,&stored_settings);
     return;
}


int main()
{
     char c;
     int i;

     /* Call function to set terminal to buffer by only one char
     /* and deliver it inmediately, so we can now use getchar().
      */
     set_keypress();

     while ((c = getchar()) != EOF) {
	  if (c == 'q') break;
	  for (i = 0; i < 10 ; ++i)  {
	       printf("%c", c);
	  }
	  printf("\n");
     }

     /* Restore terminal to previous mode */
     reset_keypress();

     return 0;
}

Last edited by Hko; 10-10-2003 at 08:51 AM.
 
Old 10-10-2003, 08:51 AM   #7
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
Are you looking to read in non-canonical mode?

Explanation:
http://www.gnu.org/manual/glibc-2.2....62.html#SEC371

Example:
http://www.gnu.org/manual/glibc-2.2..../libc_365.html

(Sorry, I am sadly well away from a linux machine to test this out on)
 
Old 10-10-2003, 08:51 AM   #8
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
OKay, should have refreshed before posting that one!
 
Old 10-10-2003, 08:55 AM   #9
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Does this help?
http://www.linuxquestions.org/questi...hreadid=102330

Oops, wrong thread... Sorry

Last edited by Hko; 10-10-2003 at 09:34 AM.
 
Old 10-10-2003, 09:32 AM   #10
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Original Poster
Rep: Reputation: 33
Thanx Hko your program works great.
But, I would like to do it using ncurses ... Any suggestions

The link which you posted this link again....Plz check again.

P.S :- I have been asked to do it using ncurses . Plz help me with the functions I am supposed to use ...
 
Old 10-10-2003, 09:39 AM   #11
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally posted by SaTaN
Thanx Hko your program works great.
But, I would like to do it using ncurses ...
Using ncurses or not not, you will still need to do the same thing as in my example, I'm afraid...
 
Old 10-10-2003, 09:44 AM   #12
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Original Poster
Rep: Reputation: 33
I have been asked to do it using ncurses and I don't want to learn ncurses from the scratch .
I am finding it really hard to understand ncurses ... I googled and found some sites which had info. but I amn't finding them quite good.
Can anyone plz suggest books/sites from which I can read abt ncurses

Maybe there are some functions in ncurses lib which will help me regarding taking character by character input.....

Actually what I want to do is implement "talk" in unix using C.
I have written "write" command using FIFOS [Though not as good as the one in unix....] Though maybe adding this thing and some other things would help...

Last edited by SaTaN; 10-10-2003 at 09:51 AM.
 
Old 10-10-2003, 10:08 AM   #13
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
I had to write a "talk" program back in college using sockets, but it was not curses.

I'd suggest finding the source for your favorite ncurses program and see how they use it.
 
Old 10-10-2003, 10:22 AM   #14
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
The book "Beginning Linux Programming (2nd Edition)" has a chapter about ncurses. You can download the (GPL'd) sources for the examples in this book here:

http://www.wrox.com/dynamic/books/download.aspx

I think it may be useful even without the book. Chapter 6 is about ncurses, and chapter 5 has a kbhit() (remember Borland on DOS?) program, similar to the example I posted.

Hope this helps.
 
Old 10-11-2003, 09:33 AM   #15
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Original Poster
Rep: Reputation: 33
Quote:
Originally posted by crabboy

I'd suggest finding the source for your favorite ncurses program and see how they use it.
I didn't get you.
 
  


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
Fedora Core 2: Screen Resolution can not change from "800X600" to "1024X 768" suhaimi_sj Fedora - Installation 18 12-17-2009 03:29 AM
how can i change my vga driver from "vesa" to "savage" mojarron Slackware - Installation 1 03-24-2005 11:03 PM
how can i change my vga driver from "vesa" to "savage" mojarron Slackware 1 03-24-2005 07:16 AM
"connect: No buffer space available" in my local network area SpaceCowboy Linux - Networking 5 08-30-2004 02:44 AM
Can you change the "title" under your name that says "member" or "newbie&qu Whitehat LQ Suggestions & Feedback 3 11-19-2003 06:32 PM

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

All times are GMT -5. The time now is 06:56 AM.

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