mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
29 lines
677 B
Plaintext
29 lines
677 B
Plaintext
module madlibs;
|
|
import regex, stdio;
|
|
|
|
fn void main()
|
|
{
|
|
printn("Enter a story template, terminated by an empty line:");
|
|
String story = "";
|
|
while (try String line = stdin().readline(mem).strip())
|
|
{
|
|
|
|
story = story.append(line);
|
|
story = story.append("\n");
|
|
}
|
|
|
|
Regex r;
|
|
|
|
r.initWithOptions("<.+?>", RegexOpt.GLOBAL)!!;
|
|
defer r.destroy();
|
|
|
|
foreach (RegexMatch* match : r.match(story))
|
|
{
|
|
VarString s = match.string;
|
|
printf("Enter a value for '%s': ", s[1..^2]);
|
|
String word = stdin().readline(mem).strip()!;
|
|
story = story.replace(s, word);
|
|
}
|
|
|
|
printn("\nThe story becomes:\n%s\n", story);
|
|
} |