1. Help in a Simple Program
- Posted by Euphoric_Kid Nov 17, 2011
- 1279 views
- Last edited Nov 18, 2011
This program was in Euphoric Mysteries book, I just added whatever to stop the program at the end. When I enter Euphoria as password when program runs it shows Access Denied. But when I change password=password[1..length(password)-2], then it works fine. Why???
object password, whatever puts(1,"Enter your password: ") password = gets(0) password = password[1..length(password)-1] if compare(password,"Euphoria")=0 then puts(1,"[Password Authenticated]") else puts(1,"[Incorrect password - Access Denied!]") end if whatever=gets(0)
[edit: added eucode tags. --Matt]
2. Re: Help in a Simple Program
- Posted by DerekParnell (admin) Nov 17, 2011
- 1287 views
When I enter Euphoria as password when program runs it shows Access Denied. But when I change password=password[1..length(password)-2], then it works fine. Why???
There is a bug in Euphoria when it comes to reading console input in a Windows system. The line ending should be a single LF (#0A) character, but in Windows we are getting a CRLF (#0D#0A) combination. Try this instead.
object password, whatever puts(1,"Enter your password: ") password = gets(0) if password[$] = 10 then password = password[1..$-1] end if if password[$] = 13 then password = password[1..$-1] end if if compare(password,"Euphoria")=0 then puts(1,"[Password Authenticated]") else puts(1,"[Incorrect password - Access Denied!]") end if whatever=gets(0)
If you are using Eu4, then a simplier way is ...
include std/text.e object password, whatever puts(1,"Enter your password: ") password = trim(gets(0)) if equal(password,"Euphoria") then puts(1,"[Password Authenticated]") else puts(1,"[Incorrect password - Access Denied!]") end if whatever=gets(0)
3. Re: Help in a Simple Program
- Posted by euphoric (admin) Nov 17, 2011
- 1276 views
When I enter Euphoria as password when program runs it shows Access Denied. But when I change password=password[1..length(password)-2], then it works fine. Why???
To return from the gets(0) function, you have to press Enter, right? That Enter character is appended to whatever you typed, so your sequence looks like
"Euphoria\n"
Using the $-1 truncates the \n and gives you the pure "Euphoria."
You could also use:
password = prompt_string( "Enter your password: " )
and not worry about it.
I think.
Oops: Didn't see you were using "$-2" and didn't know about the bug pointed out by DerekP. My solution still stands, however.
4. Re: Help in a Simple Program
- Posted by dr_can Dec 21, 2011
- 1210 views
prompt_string in Eu 4.0.3 doesn't work as the manual states, at least when used in Windows. It strips the #10 but not the #13.
5. Re: Help in a Simple Program
- Posted by DerekParnell (admin) Dec 21, 2011
- 1137 views
prompt_string in Eu 4.0.3 doesn't work as the manual states, at least when used in Windows. It strips the #10 but not the #13.
This is a known bug and has already been fixed for the next release.
The problem is that under Windows, gets() returns a string terminated with CRLF rather than just a LF.
As a workaround for now, use the trim() function on the string returned by prompt_string().
include std/text.e include std/comsole.e sequence ans ans = trim(prompt_string("Question:"))