mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
34 lines
757 B
Plaintext
34 lines
757 B
Plaintext
module madlibs;
|
|
import regex, stdio;
|
|
|
|
func void main()
|
|
{
|
|
println("Enter a story template, terminated by an empty line:");
|
|
string story = "";
|
|
while (1)
|
|
{
|
|
try string line = stdin.readln().strip();
|
|
if (!line.size) break;
|
|
story += line + "\n";
|
|
}
|
|
|
|
Regex r;
|
|
|
|
r.initWithOptions("<.+?>", RegexOpt.GLOBAL) else @unreachable;
|
|
defer r.destroy();
|
|
|
|
foreach (RegexMatch* match : r.match(story))
|
|
{
|
|
string s = match.string;
|
|
printf("Enter a value for '%s': ", s.slice(1, s.size - 2));
|
|
try string word = strin.readln().strip();
|
|
story = story.replace(s, word);
|
|
}
|
|
|
|
println("\nThe story becomes:\n%s\n", story);
|
|
|
|
catch (error e)
|
|
{
|
|
// Ignore any error
|
|
}
|
|
} |