![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2006
Posts: 10
Rep Power: 0
![]() |
Hello. I am having an issue with a program I am creating. Basically, it is a simply UDP chat client/server, that reads input from stdin in raw mode.
My issue is that I need to keep track of what has been typed, as I am reading character by character. Here is my code: Note: char input[256]; //if the input is done, then reinitialize
if(inputdone) {
//clear the input array
memset(input, '\0', sizeof(input));
//reset c
c = 0;
//reset inputdone
inputdone = 0;
}
//get a char
input[c] = getchar();
//if it is a newline, then they are done typing
if(input[c] == '\n') {
//get rid of the newline
input[c] = '\0';
//set inputdone to true
inputdone = 1;
} else if(input[c] == '\b') {
//HELP HERE
//clear the current input
input[c] = '\0';
//it is a backspace so go backwards
c--;
if(c <= 0) c = 0;
//clear whatever used to be here
input[c] = '\0';
} else {
//increment the array
c++;
//make sure it doesnt go past the size of input
if(c > 256) c = 256;
}This code is all tucked into a while(1) that constantly prints out the contents of input (with a bunch of backspaces first to clear the previous printf). Remember, it is in raw mode. Basically, when I run this code, the cursor goes back successfully, but the character still shows. For example: If I type "abcd", then hit backspace, it will still say "abcd" but the cursor will now be on "c". Does this make sense? Thanks in advance. |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
Have you tried printing over the character? You could trying going back one char, printing a space, then stepping back again.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2006
Posts: 10
Rep Power: 0
![]() |
Ah, thanks for the suggesstion.
It required a little more fiddling than JUST that, but it got me on the right track. Thanks. |
|
|
|
|
|
#4 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
Wouldn't it be way easier to use the fgets function?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| relation between array and pointer | n00b | C++ | 6 | Oct 12th, 2006 4:38 PM |
| incrementing character array elements value | n00b | C++ | 7 | Jun 24th, 2006 4:44 AM |
| Change the size of a character array dynamically? | bivhitscar | C | 23 | Nov 5th, 2005 6:55 AM |
| Installing IPB 2.03 | bh4575 | Other Web Development Languages | 0 | Apr 23rd, 2005 3:36 AM |
| Simple question: Easiest way to search through a character array | willz99ta | C++ | 6 | Mar 26th, 2005 3:15 AM |