diff options
| author | Cliff Click <cliffc@acm.org> | 2026-10-24 15:23:20 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-10-24 15:23:20 -0700 |
| commit | f49b184a093ab5f653ac36ccc4939c45515a2f4b (patch) | |
| tree | 36b7b0b688a6b03ceb1412fc45f79f32e7540002 /chapter28b/docs/examples/Capitalize.smp | |
| parent | a216a23bbd4d6e05a40d86ec8e76c038e945f3ba (diff) | |
| download | Simple-f49b184a093ab5f653ac36ccc4939c45515a2f4b.tar.gz Simple-f49b184a093ab5f653ac36ccc4939c45515a2f4b.zip | |
Move combined chapter 25 baseline to chapter 28b
Diffstat (limited to 'chapter28b/docs/examples/Capitalize.smp')
| -rw-r--r-- | chapter28b/docs/examples/Capitalize.smp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/chapter28b/docs/examples/Capitalize.smp b/chapter28b/docs/examples/Capitalize.smp new file mode 100644 index 00000000..8e31c18f --- /dev/null +++ b/chapter28b/docs/examples/Capitalize.smp @@ -0,0 +1,22 @@ + +// An implementation of +// https://sampleprograms.io/projects/capitalize/ + +val main = { u8[~][] args -> + if( args# > 2 ) { + sys.io.p("Use quotes around multiple strings.\n"); + return 0; + } + if( args# != 2 || args[1]# == 0 ) { + sys.io.p("Usage: please provide a string\n"); + return 0; + } + + u8[~] input = args[1]; + var output = new u8[input# + 1]; + sys.ary.copy(output,0,input,0,input#); + output[0] = sys.char.toupper(input[0]); + output[input#] = '\n'; + sys.io.p(output); + return 0; +}; |
