Kish Shen wrote: > On 21/09/2011 18:22, Sergey Dymchenko wrote: >> Sorry for probably stupid question, but I can't find an answer. >> >> How to read an integer from user? >> read(N) requires user to end input with dot, >> read_line(N) returns a string, not an integer... >> >> Sergey. >> > > Hi, > > If you use ECLiPSe's help/1 with the query "help read.", this would give > you a list of all builtins whose name has read in it (a predicate that > provides the functionality you want is likely to have read as part of > its name), including > > read_token/2 and read_token/3, which is probably what you want - call it > with Class set to integer: > > read_token(stream, X, integer) > In Sergey's case, a better choice might be the combination read_string(Stream, end_of_line, _, String), number_string(X, String), integer(X) because (unlike read_token) it handles negative numbers and it will fail if there are any junk characters after the number (read_token would just leave these unread). -- JoachimReceived on Wed Sep 21 2011 - 19:14:57 CEST
This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST