Inserting One Character at a Time in Java

Draw QR Code ISO/IEC18004 in Java Inserting One Character at a Time
Inserting One Character at a Time
QR Recognizer In Java
Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications.
The insch() function inserts only one character into a row of text, shoving all the characters to the left one space to the left. And like insertln(), any character that gets shoved off the left side of the screen is forgotten; no wrapping takes place with insch(). The following source code in Listing 5-4 is one of those classic chestnuts, the scrolling marquee. Of course, it s a lot easier to write, thanks to the insch() function.
Encoding QR Code ISO/IEC18004 In Java
Using Barcode encoder for Java Control to generate, create QR-Code image in Java applications.
Listing 5-4: marquee1.c
QR Recognizer In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
1 2 3 4 5 6 7 8 9 #include <ncurses.h> #include <string.h> int main(void) { char text[] = Stock Market Swells! DOW tops 15,000! ; char *t; int len;
Painting Bar Code In Java
Using Barcode encoder for Java Control to generate, create bar code image in Java applications.
(continued)
Barcode Recognizer In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
5
Quick Response Code Creator In C#
Using Barcode creation for Visual Studio .NET Control to generate, create Denso QR Bar Code image in Visual Studio .NET applications.
More Text Manipulation
QR Code Creator In Visual Studio .NET
Using Barcode creation for ASP.NET Control to generate, create Quick Response Code image in ASP.NET applications.
Listing 5-4 (continued)
Encode Quick Response Code In .NET
Using Barcode generator for .NET framework Control to generate, create Denso QR Bar Code image in .NET framework applications.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 initscr(); len = strlen(text); t = text; /* initialize pointer */ while(len) { move(5,5); /* always insert at the same spot */ insch(*(t+len-1)); /* work through string backwards */ refresh(); napms(100); /* .1 sec. delay */ len--; } getch(); endwin(); return 0; }
Printing Denso QR Bar Code In Visual Basic .NET
Using Barcode encoder for .NET Control to generate, create QR Code image in VS .NET applications.
Each character in the string is processed backward in the while loop (lines 14-21), from the end to the beginning. The *(t+len-1) calculation initially points to the last character in the string, based on its length len (with the t pointer always pointing at the start of the string). As the while loop decrements the value of len, the *(t+len-1) calculation points to each previous character in the string. The insch() function then displays that character at location 5,5, pushing the rest of the text on that line one notch to the left. The result is the scrolling marquee.
Generate GS1-128 In Java
Using Barcode maker for Java Control to generate, create UCC.EAN - 128 image in Java applications.
A More Visual Example
Encoding UPCA In Java
Using Barcode drawer for Java Control to generate, create UPC Symbol image in Java applications.
The following code in Listing 5-5 modifies the original MARQUEE1.C source code, filling the screen with text so that you can more graphically see how the insch() function affects text on the screen.
Barcode Creation In Java
Using Barcode generator for Java Control to generate, create barcode image in Java applications.
Listing 5-5: marquee2.c
Make 2/5 Industrial In Java
Using Barcode printer for Java Control to generate, create 2 of 5 Industrial image in Java applications.
1 2 3 4 5 6 7 8 9 10 11 12 #include <ncurses.h> #include <string.h> void fill(void); int main(void) { char text[] = Stock Market Swells! DOW tops 15,000! ; char *t; int len; initscr();
Make Code 128C In VS .NET
Using Barcode maker for ASP.NET Control to generate, create Code 128 Code Set A image in ASP.NET applications.
5
Barcode Drawer In Visual Studio .NET
Using Barcode generation for Visual Studio .NET Control to generate, create barcode image in .NET framework applications.
Listing 5-5 (continued)
GTIN - 12 Generator In VB.NET
Using Barcode drawer for VS .NET Control to generate, create UPC-A Supplement 2 image in VS .NET applications.
More Text Manipulation
Code128 Generation In Visual Basic .NET
Using Barcode encoder for VS .NET Control to generate, create Code 128C image in Visual Studio .NET applications.
13 14 fill(); 15 refresh(); 16 len = strlen(text); 17 t = text; /* initialize pointer */ 18 while(len) 19 { 20 move(5,5); /* always insert at the same spot */ 21 insch(*(t+len-1)); /* work through string backwards */ 22 refresh(); 23 napms(100); /* .1 sec. delay */ 24 len--; 25 } 26 getch(); 27 28 endwin(); 29 return 0; 30 } 31 32 void fill(void) 33 { 34 int a,x,y; 35 36 getmaxyx(stdscr,y,x); 37 for(a=0; a<y; a++) 38 addstr( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z\n ); 39 }
Code 3/9 Creator In Visual Basic .NET
Using Barcode generation for Visual Studio .NET Control to generate, create ANSI/AIM Code 39 image in .NET framework applications.
Less of Hamlet
UCC-128 Maker In VS .NET
Using Barcode encoder for .NET Control to generate, create UCC-128 image in VS .NET applications.
On the deleting side, NCurses offers the delch() and deleteln() functions. My favorite is delch() because I can pronounce it. Even so, the following source code in Listing 5-6 shows deleteln() first. It s a modification of the original HAMLET.C source code, which makes typing easier.
EAN 128 Generator In .NET
Using Barcode generation for ASP.NET Control to generate, create EAN128 image in ASP.NET applications.
Listing 5-6: hamlet4.c
1 2 3 4 5 6 7 8 #include <ncurses.h> int main(void) { char Ham1[] char Ham2[] char Ham3[] char Ham4[]
= = = =
To be, or not to be: that is the question:\n ; Whether tis nobler in the mind to suffer\n ; The slings and arrows of outrageous fortune,\n ; Or to take arms against a sea of troubles,\n ;
(continued)
5
More Text Manipulation
Listing 5-6 (continued)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 char Ham5[] = And by opposing end them \n ; initscr(); addstr(Ham1); addstr(Ham2); addstr(Ham3); addstr(Ham4); addstr(Ham5); refresh(); getch(); move(1,0); deleteln(); refresh(); getch(); endwin(); return 0; }
/* wait for key press */ /* move to the line to delete */ /* Delete and backscroll */ /* wait for key press */
First, the whole chunk of text is displayed. Good. Press Enter to delete the text. Note how it scrolls up Yes, the deleteln() function is nearly the opposite of the insertln() function, complete with logical reverse scrolling. And the vanished line goes off into bit-hell as well; don t look for it anywhere. Do note that deleteln() does not affect the location of the cursor. After the last refresh() command above, the cursor is still at location 1,0, eagerly awaiting more text to be added to the screen.
Goodbye, Chunk of Text!
It s time to edit Hamlet s speech. Your job is to display the text, then press a key to delete the word outrageous. The command to use is delch(), which has no arguments. It simply removes whichever character happens to be lurking at the current cursor position. Any characters to the right on the same line are then shuffled over left one notch; a blank character is then added to the end of the line. Hint: outrageous is 10 characters long, but you probably also want to delete the space character immediately after it. So 11. Here s another hint: Row 2, Column 25. You should be able to see the text displayed, press a key, and then watch as the word outrageous vanishes. Such tidy editing.