How to compare a string to a string in Forth? -
how compare 2 strings in forth?
and can in if
statement or should make helper boolean variable? here's code have far. way, iox@
input user.
: var compile: variable complile: ; : lock compile: var realpass$ compile: realpass$ "password" ! compile: ." enter password: " compile: var pass$ compile: iox@ pass$ ! compile: var match compile: realpass$=pass$ match ! unknown token: realpass$=pass$
the ansi word compare strings compare (c-addr_1 u_1 c-addr_2 u_2 -- n)
. n equals 0 if 2 strings compared equal. forth eschews explicit variables in favor of using stack using if
directly without variable fine.
: pwcheck compare if ." entry denied." else ." welcome friend." cr ; s" hello" ok s" goodbye" ok pwcheck not wanted here. ok s" howdy" ok s" howdy" ok pwcheck welcome friend. ok
Comments
Post a Comment