public static void main (string[] args) { int c; stdout.printf ("Type something and press enter. Type '0' to quit\n"); do { c = stdin.getc (); if (c > 10) { stdout.printf ("%c (%d)\n", c, c); } } while (c != '0'); }
[CCode (lower_case_cprefix = "", cheader_filename = "readline/readline.h")] namespace ReadLine { [CCode (cname = "readline")] public extern string? read_line (string prompt = ""); public extern void add_history (string line); } void main () { while (true) { var name = ReadLine.read_line ("Please enter your name: "); if (name != null && name != "") { stdout.printf ("Hello, %s\n", name); ReadLine.add_history (name); } } }
/* * We use the fact that char[] allocates space * and that FileStream.gets takes a char[] but returns a string! * * Note that stdin.gets uses the "safe" fgets(), not the unsafe gets() */ string read_stdin () { var input = new StringBuilder (); var buffer = new char[1024]; while (!stdin.eof ()) { string read_chunk = stdin.gets (buffer); if (read_chunk != null) { input.append (read_chunk); } } return input.str; } int main () { string name = read_stdin (); stdout.printf ("\n-----\n%s\n", name); return