China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-01 03:55
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » [Original] NOBLANK implementation in BAISIC and C View 1,022 Replies 1
Original Poster Posted 2003-08-02 00:00 ·  中国 陕西 西安 教育网
高级用户
★★
OS/2女孩
Credits 639
Posts 183
Joined 2003-06-14 00:00
23-year member
UID 5148
Gender Female
Status Offline
*****************************************
*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
*lemonhall@vip.sina.com 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;
}
}
REM 喜欢DOS,因为它的简单
REM 喜欢OS/2,因为它不再矫饰
REM 喜欢BASIC,因为它并不幼稚
REM 喜欢GNU,因为它杂乱无章
Floor 2 Posted 2003-08-02 00:00 ·  中国 安徽 滁州 天长市 电信
银牌会员
★★★
Credits 1,833
Posts 648
Joined 2002-11-08 00:00
23-year member
UID 197
Gender Male
Status Offline
Support original work!!!
Forum Jump: