The following function capitalizes each word in a string.
It has one parameter, named input, and five
local variables, which are written as extra parameters.
# capitalize each word in a string
function capitalize(input, result, words, n, i, w)
{
result = ""
n = split(input, words, " ")
for (i = 1; i <= n; i++) {
w = words[i]
w = toupper(substr(w, 1, 1)) substr(w, 2)
if (i > 1)
result = result " "
result = result w
}
return result
}
# main program, for testing
{ print capitalize($0) }