Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 07-22-2004, 04:00 AM   #1 (permalink)
toblerone
Registered User
 
toblerone's Avatar
 
Join Date: Jul 2004
Posts: 11
toblerone is on a distinguished road
Question read input without needing a newline character?

hi
i got a proj to make a basic text prediction prog.
initial ideas are good but i need to know if there is a way to read in chars without the user keying enter - so as the user types.

i am a relative amatuer using borland and/or visual C and would really appreciate some help

Does this Q show that im absolutly dumb or is the answer unknown??

Last edited by toblerone; 07-29-2004 at 02:54 AM.
toblerone is offline   Reply With Quote
Old 07-23-2004, 02:29 AM   #2 (permalink)
Amaranthine
Registered User
 
Amaranthine's Avatar
 
Join Date: May 2004
Posts: 47
Amaranthine is on a distinguished road
I'm an amateur as well so I don't guarantee this will work but could you do it with a WM_CHARDOWN message?
Amaranthine is offline   Reply With Quote
Old 07-29-2004, 02:52 AM   #3 (permalink)
toblerone
Registered User
 
toblerone's Avatar
 
Join Date: Jul 2004
Posts: 11
toblerone is on a distinguished road
I cant find a wole lotta info on the WM_CHARDOWN option
but thought of another idea instead....
is it possible to delete a newline character?
something like using the \b ?.. this would mean i could use a scanf then printf to delete the newline necessary to complete the scanf.
toblerone is offline   Reply With Quote
Old 07-29-2004, 04:58 AM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,695
redhead is on a distinguished road
There is no standard way of activating on key-press which is what you're trying here.
It is very system dependant, thus in order to help you with this specific issue, you need to tell us what compiler/OS you want this program to run with.
Quote:
is it possible to delete a newline character?
something like using the '\b' ?.. this would mean i could use a scanf then printf to delete the newline necessary to complete the scanf.
The '\b' is for bell, the '\r' will return the cursor to position 1 on the line, meaning if you print anything like:
Code:
int counter = 0;
while(counter < 10)
{
    printf(" This is my counter: %d\r", counter++);
    sleep(3);
}
printf("\n");
The line "This is my counter: (number)" will remain on the same line and keep on overwriting previus printed lines, thus only showing current counter number.
The '\r' will in no way affect the scanf() call, since it is bound to STDOUT and not STDIN which scanf() reads from.
So you need to work around stripping the '\n', but this is easy, just read it with scanf(), getline(), fscanf() or whatever and then use strlen() on it later on, like:
Code:
int length = 50;
char line[length];
printf("Enter your text, and terminate with ^D\n\n");
while (fgets(line, length, stdin) > 0)
{
    while(line[strlen(line)] == '\r' || 
          line[strlen(line)] == '\n') 
        line[strlen(line) - 1] = '\0';
    /* 
     * do what you want with line, it is holding the 
     * text written, without <cr> or '\n' in it.
     * It could be a correction to the writer ie:
     *          Your line of text: "He took ione C++ course"
     *          Shouldn't it be  : "He took one C++ course" ?? (Y/N)
     */
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001

Last edited by redhead; 07-29-2004 at 05:56 AM.
redhead is offline   Reply With Quote
Old 07-29-2004, 06:04 PM   #5 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
Quote:
Originally posted by redhead
The '\b' is for bell
no, '\b' is backspace, '\a' is bell.

Quote:
the '\r' will return the cursor to position 1 on the line
not necessarily. on some terminals it is a newline, on some it has no effect. if stdout is directed to a file or another program, '\r' will be literally inserted into the stream.

Quote:
The line "This is my counter: (number)" will remain on the same line and keep on overwriting previus printed lines, thus only showing current counter number.
hmm, doesn't work on my stdout (linux bash). perhaps an fflush() will fix it.
joe_bruin is offline   Reply With Quote
Old 08-03-2004, 03:49 AM   #6 (permalink)
toblerone
Registered User
 
toblerone's Avatar
 
Join Date: Jul 2004
Posts: 11
toblerone is on a distinguished road
Smile

your replies have shed light into some corners. thanks.
I wanted the prog to be fairly portable so no compiler dependency.
hmm ....




Time is that quality that stops evrything happening at the same time,
lately it dosent seem to be working.
toblerone is offline   Reply With Quote
Reply

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
text file recursive string reading C toblerone Standard C, C++ 4 08-04-2004 10:05 PM
[MySQL] blob vs text redhead PHP 2 03-29-2004 11:15 PM
edit? anon Lounge 10 11-21-2002 03:02 PM


All times are GMT -8. The time now is 04:00 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting