Use {ok, [X]} = io:fread("","~d")(brackets around X).
freadreturns the list as the second element of the tuple (which makes sense if you are reading more than one token), so you need to get the element from the list before you can compare it with 42.
Note that instead of matching patterns by the result ==, you can simply match the pattern by X itself, that is:
case X of
42 -> io:fwrite("Hi\n");
_ -> io:fwrite("Hello\n")
end.
source
share