- in - FMT-STRING - a string containing "%" specifiers as documented for the unix "printf" command.
- Specifiers recognized by sfmt include d, f, s, u, c, x, X, b, o and qualifiers l, ll. Precision, +/- components are recognized. A "%" character can be inserted with "%%".
- sfmt checks if ITEMS match the types of corresponding specifiers in FMT-STRING. If a type mismatch is evident, an error message is printed to the terminal and an empty string returned.
- in - ITEMS - data to be formatted. Must match the types of specifiers. Number of specifiers in the format string must equal the number of ITEMS.
- returns: formatted string or #f on error.
(import scheme.base nutils)
(define op (open-output-file "Report-doc.txt"))
(printnl (sfmt "%-18s %-14s %-15s %-13s %s"
"Title" "Author" "Pub. Date" "Dept." "Cost")
prn: op )
(printnl (sfmt "%-18s %-14s %-15s %-13s %s"
"------------" "-------" "----------" "------" "-------")
prn: op)
(printnl (sfmt "%-18s %-14s %-15s %-8d %12.2f"
"Report No. 122" "Sam Jones" "2024-08-15" 1405 1223.57)
prn: op)
(close-output-port op)