![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-10-31 11:02 |
47,815 topics / 349,930 posts / today 0 new / 48,290 members |
| DOS开发编程 & 发展交流 (开发室) » [Original] NOBLANK implementation in BAISIC and C |
| Printable Version 1,260 / 1 |
| Floor1 lemonhall | Posted 2003-08-02 00:00 |
| 高级用户 Posts 183 Credits 639 | |
|
*****************************************
*The following two sample programs were written entirely by lemonhall and ran *successfully, but have not been rigorously tested. *Please do not repost them freely without permission [email protected] QQ:313813 *************************************** Passed under Qbasic1.0/Quick Baick 4.5 A sample program that removes double spaces from input and turns them into single spaces =============================================== 'create an oversized buffer DIM c$(999) 'initialize the counter n = 1 CLS 'use a loop to simulate the corresponding getchar function DO UNTIL c$(n - 1) = CHR$(13) 10 c$(n) = INKEY$: IF c$(n) = "" THEN 10 PRINT c$(n); n = n + 1 LOOP 'a counter with the same name is used, which is a very bad habit n = 1 'the corresponding define NOBLANK 'a' lc$ = "a" 'the loop is completely "copied" from the core logical operation of C language 'where those beginning with s represent a state 'the IF structure is used to explicitly declare the binary state DO UNTIL c$(n) = CHR$(13) IF c$(n) " " THEN sc = 1 ELSE sc = 0 END IF IF lc$ " " THEN slc = 1 ELSE slc = 0 END IF 'perform a BAISC logical operation, this is the core of the test ss = sc OR slc IF ss 0 THEN PRINT c$(n); lc$ = c$(n) n = n + 1 LOOP ========================================= = Corresponding C language implementation (modified Berkeley C) = ========================================= #include /*a statement that's a bit hard to understand at first*/ #define NOBLANK 'a' main() /*replace string of blanks with a single blank */ /*This doesn't need translating, right?*/ { int c,lastc; lastc=NOBLANK; while((c=getchar())!=EOF) { if (c!=' '||lastc!=' ' ![]() putchar(c); lastc=c; } } |
|
| Floor2 LanE | Posted 2003-08-02 00:00 |
| 银牌会员 Posts 648 Credits 1,835 | |
|
Support original work!!!
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |