NAME

iread, sread - Pop up a dialog prompting the user for input

SYNOPSIS

iread( p )
sread(
s, p )

DESCRIPTION

iread() brings up a pop-up dialog asking the user to enter an integer, using the string referenced by p as the message in the dialog.

sread() pops up a dialog prompting the user for a string as input, using the second argument p as the message in the dialog. The string entered by the user is copied into the memory starting at the address passed as the first argument s. The null terminator is also copied over.

If p is not provided in either function, the dialog box does not contain a prompt.

RETURN VALUE

iread() returns the numeric value of the integer entered by the user. Note that Tranquility only has support for integers and will truncate fractional numbers.

sread() has no return value.

NOTES

The syntax of iread() allows it to be used without being assigned to a variable without errors. If not set to a variable or present in an arithmetic equation then the data entered will be lost.

EXAMPLES

The following example sets n to be 5 times the value entered by the user.

fun init() {
     var n


     n : 5 * iread("Enter an integer:")
     iprint(.n)
}

The following example takes in a 10 letter input from the user without a prompt

fun init() {
     var str

     str : alloc( 11 )
     sread( .str )
}

BUGS

The code will crash if .BR iread() is the first line of code and it’s return value is not set to a variable.

AUTHORS

Charlie Stuart cstuart11@protonmail.com
Carson Ford, Fall 21-22
Ryan Abraham, Fall 21-22

Sherry Liu, Winter 21-22

REPORTING BUGS

First, check the Tranquility Programmer’s Manual
https://www.cs.drexel.edu/~bls96/tranquility.pdf
If the problem persists see Dr. Stuart or Charlie Stuart

Dr. Stuart: brian.l.stuart@drexel.edu
Charlie Stuart: cstuart11@protonmail.com

SEE ALSO

tranqc(1), iprint(3), sprint(3), i2s(3), alloc(3)

Tranquility Programmer’s Manual
https://www.cs.drexel.edu/~bls96/tranquility.pdf