User input/Text
Zen C features a built-in shorthand for prompting user input using the ? prefix. Format specifiers are automatically inferred based on the variable's type. For the string, we define a fixed-size character array buffer to hold the input safely.
fn main() {
let str_val: char[256];
let int_val: int;
// Prompt for the string (infers %s for the char array)
? "Enter a string: " (str_val);
// Prompt for the integer (infers %d for the int)
? "Enter the integer 75000: " (int_val);
println "\nYou entered the string: ";
println "You entered the integer: ";
}
Output:
Enter a string: RosettaCode
Enter the integer 75000: 75000
You entered the string: RosettaCode
You entered the integer: 75000
Attribution: This is a community solution for the Rosetta Code task User input/Text in Zen C.
This article uses material from the Rosetta Code article User input/Text, which is released under the GNU Free Documentation License 1.3. A list of the original authors can be found in the page history.