*****************************************
*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;
}
}
*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,因为它杂乱无章
REM 喜欢OS/2,因为它不再矫饰
REM 喜欢BASIC,因为它并不幼稚
REM 喜欢GNU,因为它杂乱无章


