g | x | w | all
Bytes Lang Time Link
024Raku Perl 6 rakudo250425T155157Zxrs
049AWK250425T154013Zxrs
001Jalapeño250316T232320ZATaco
057Zsh240911T131306Zroblogic
356Bespoke250216T101701ZJosiah W
009Husk240911T073707ZGlory2Uk
008Perl 5 + p040240911T075453ZDom Hast
005Thunno 2 Ṡ230614T171909ZThe Thon
009Jelly160620T073536ZDennis
058C89 clang220702T220827Zc--
310brainfuck220329T022532Zengineer
085C 85 Bytes220327T224132Zuser1117
057Factor220324T233346Zchunes
033Ly220325T015811Zcnamejj
007Japt S220324T225901ZShaggy
007Vyxal s220324T045245Zemanresu
059Python 3210511T024926ZMakonede
116Lexurgy220324T160728Zbigyihsu
059JavaScript210311T104443Zuser1006
00805AB1E190508T072013ZKevin Cr
135Java 8190508T031312ZBenjamin
012Brachylog190508T001720ZUnrelate
089VTL2190507T191031Zbrhfl
035Perl 6190506T213431Zbb94
666JavaScript190506T210508Zzfrisch
005V160620T074537ZDJMcMayh
nanslang161026T165946ZErik the
nanGNU sed150511T095054Zdieter
010Vim160620T071454ZDJMcMayh
167Java150805T183732ZVartan
nan150511T043618Zedc65
030KDBQ150522T150928ZWooiKent
093R150512T001256ZMickyT
051Rebol150513T183653Zdraegtun
069Groovy150514T161608Zdbramwel
187C# Linq150514T130609Zldam
074C150513T222332ZToby Spe
nan150513T155144ZMegaTom
142Java150513T190755ZRuben Di
101Python 3150513T152935ZTim
059Python 3150512T080009Zgcx11
074PHP150511T132421Zmanatwor
025Perl Version < 5.18150511T022352Zhmatt1
063Python 2150511T165732Zmbomb007
123C#150512T125434ZTransmis
174Java150511T164114ZTNT
069Haskell150511T171040Zlynn
nanJAVA150511T161153ZAngelo T
104JavaScript regex solution150512T062030ZIQAndrea
061Lua150511T220043Zuser4073
273JAVA150511T021121ZAtul Kum
056Python 3150511T141656ZSp3000
013Perl150511T212511ZThisSuit
nanPHP 64150511T092914ZOctfx
105R150511T044637ZAlex A.
066Mathematica150511T202032ZLegionMa
131C#150511T034345ZBlorgbea
049CSS 2.1150511T183734ZOriol
014CJam150511T174548Zjimmy230
063C150511T131408ZAndrea B
9130PHP150511T125453ZIsmael M
039><> Fish150511T131600Zrandomra
013CJam150511T001517ZDennis
082PHP150511T125010Zkuldeep.
127Haskell150511T120401Zpoida
046Ruby150511T091529Zmanatwor
015CJam150510T234353ZMartin E
125C150511T081155ZMarcDefi
073Python 2150511T074049ZLogic Kn
nanPip150511T035815ZDLosc
061Bash150511T024657ZDigital
077Javascript ES6150511T013324Znderscor
020Pyth150511T001954ZJakube

Raku (Perl 6) (rakudo), 24 bytes

print .tc~" " for @*ARGS

Attempt This Online!

AWK, 49 bytes

{for(;i++<NF;printf$i)$(i-1)~" "&&$i=toupper($i)}

Attempt This Online!

Jalapeño, 1 bytes

T

Hex-Dump of Bytecode

       0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
0000: 2d                                              

The Title Case function in Jalapeño happens to have this exact behaviour.

Try it Online!

Jalapeño, 12 bytes

w↦{₃⇤U‥⇥ₓ{₂↔-1w₋

Hex-Dump of Bytecode

       0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
0000: 18 d0 c7 d8 2b 2e df c6 d6 51 31 16             

Explained

w↦{₃⇤U‥⇥ₓ{₂↔-1w₋
w↦{₃        # Split into words, map over
  ⇤U        # The first character, uppercase
  ‥         # Concatenated with
  ⇥ₓ{₂      # The last N characters
    ↔-1     # Length of the word minus 1
w₋          # Unword, Join by spaces.

Non-trivial solution

Try it Online!

Zsh, 57 bytes

k=\ ;for i (${(s::)1}){((#k-32))||i=$i:u;printf $i;k=$i;}

Try it online!  57b hacky sed thing  81bytes


Regex solution, 47 bytes + 30 penalty :(

<<<${(U)1:0:1}${${1:1}//(#m) ##(?)/${(U)MATCH}}

Try it online!

Bespoke, 368 356 bytes

-12 bytes by taking ch to the power of itself, which errors out upon EOF.

ASCII in;initial letters in text go huge;whatever end is,I do same way
and I do the changing if chr is lowercase letter,with use of ASCII formulas
so sentence continues til at end,at earliest character matching value0with a certain formula
it really is math;RegExp is not in use as commands
these words in my code-golf made it all do work required for an A

I had a lot of fun trying to golf this one. The biggest insight here was turning the structure of the program into two nested blocks, which implicitly end at the end of the program.

The same program in "mnemonic" form:

INPUT CH
CONTROL DOWHILE
    DO COPY
    DO COPY
    STACKTOP POW
    DO P
    DO COPY
    PUT XXX:I BI TRI;STACKTOP LT
    PUT XX:DIGITNINE SEXTET
    PUSH TRI DO COPYN
    STACKTOP LT
    STACKTOP PRODUCTOF
    PUT XX:TRI BI;STACKTOP PRODUCTOF
    STACKTOP MINUS
    PUSH I
    CONTROL DOWHILE
        DO SWITCH
        DO COPY
        OUTPUT CH
        PUT XX:TRI BI;STACKTOP MINUS
        INPUT CH
        DO COPY
        PUSH FOUR DO ROT
        DO COPY
        STACKTOP POW
        DO P

Husk, 9 bytes

wmΓo:ax"

Try it online!

This is the perfect case to use the Γ function, even though this submission is not competing!

A description of the usage of Γ can be found in the thread "Tips for golfing in Husk". Briefly, Γ can apply two different functions on the list head and its tail. In this given challenge the tail modification has be ignored (only the first letter get capitalized) and so, the construction is following: Γo:a.

A special care has been taken to preserve the spaces, since splitting and then reassembling a string with w replaces multiple spaces with a single one (as well as it removes the heading and trailing spaces). I have used x with a literal space (note that in the code snippet there is a space after the quotation mark). This way an empty string is produced between each pair of spaces and by a later reassembling of the total string there will be inserted the right number of spaces.

Otherwise the submission is pretty trivial.

Explained:

      x"  # split the string on literal spaces
 m        # map
  Γo:a    #  the capitalization of the first letter
w         # join on spaces 

Perl 5 + -p040, 8 bytes

s;.;\u$&

Try it online!

Thunno 2 , 5 bytes

OıḢRƤ

Attempt This Online!

Explanation

OıḢRƤ  # Implicit input
O      # Split by spaces
 ı     # Map over this list:
  Ḣ    #  Head extract
   R   #  Uppercase
    Ƥ  #  Prepend
       # Implicit output, joined by spaces

Jelly, 9 bytes

ṣ⁶Œu1¦€j⁶

Try it online!

How it works

ṣ⁶Œu1¦€j⁶  Main link. Argument: s (string)

ṣ⁶         Split s at spaces.
      €    Each; map this over the chunks:
    1¦       Apply this to the first character:
  Œu           Uppercase.
       j⁶  Join, separating by spaces.

C89 (clang), 60 58 bytes

c;main(a){read(0,&c,1)&&main(putchar(a?toupper(c):c)<33);}

This treats non-printable ASCII as spaces (including newlines and tabs), it could be fixed for +1 byte:

c;main(a){read(0,&c,1)&&main(putchar(a?toupper(c):c)==32);}

Try it online!

brainfuck, 342 310 bytes

>-[-[-<]>>+<]>-[->+>>>>+<<<<<]>[-<+>],[<[->>+>+<<<]>>>[-<<<+>>>]<<[->>+>+<<<]>>>[-<<<+>>>]<<[->-<]>>+<[>->>>+[+[<]>>+<+]>[-<<<<<<->>>>>>]<<<+++++[>+++++<-]>+>>+<<[<<<<[->+>>+<<<]>[-<+>]>>[[-]>>+<<]>>-[<<<[-<<<<->>>>]>>>+>-<]<<<<<->>>>-]>>[-<<<<[-]>>>>]<<<<<<[-]]>[->[-]<<<<<[->>>+>>+<<<<<]>>>[-<<<+>>>]>]<<<.,]

Try it online!

Explanation:

[
* Many constants were taken from the BF constants page on esolangs.org.
*
* Cells:
*
* true number: the true index of the cell
* fake number: the relative cell index as referenced in the code
*
* true# | fake# | info
*   0       -     Used only for initialization of (fake) cell 0
*   1       -     Used only for initialization of (fake) cell 0
*   2       -     Used only for initialization of (fake) cell 0
*   3       -     Used only for initialization of (fake) cell 0
*   4       0     Holds constant 32 / ' ', which is used for cell 5 (space flag) and for subtracting (' ') from input
*   5       1     Holds the input/output char during the main loop. Also used in setup for copying cell 0 to cell 5
*   6       2     Used to hold 32 / ' ' (temporarily, to subtract it from the input)
*   7       3     Used to hold a copy of the input that gets mangled throughout the loop, being subtracted from to 
*                 check what the input character was. Also used in space code to copy cell 0 to cell 5.
*   8       4     Used primarily as a flag to decide which part of the space/not space conditional to run (if 1, the 
*                 space code runs; if 0, the not-space code runs). Also used when copying cell 3 to 6 (for checking 
*                 if cell 3 == 0), and to copy cell 1 to 3 (input).
*   9       5     Holds the 'space flag' (different from cell 4). When a space is encountered, this cell is set to 32 
*                 ('a' - 'A'). When a lowercase character is encountered, this cell is subtracted cell 1 (input), 
*                 clearing it by default (subtraction without copying implicitly clears the cell). This makes it so
*                 that only the first character after a space is converted to uppercase.
*   10      6     Used as a temporary cell when initializing constants 65 ('a' - ' ') and 2, also used in the
*                 lowercase check loop to set cell 8 (cell 3 == 0 flag)
*   11      7     Used as the counter in the lowercase check loop, goes from 26 to 0 (decrementing each iteration).
*                 Also used as a temporary cell when initializing constant 65.
*   12      8     Used to hold (cell 3 == 0) flag, which subtracts cell 5 from cell 1 if it is 1 (which means that 
*                 cell 1 is a lowercase letter).
*   13      9     Used as a flag to figure out if the else branch of the lowercase checker should run. If one, the
*                 character is not a lowercase letter or space and so cell 5 is cleared.
]

>-[-[-<]>>+<]>-    set cell 0 to 32 (=' ') 

[->+>>>>+<<<<<]    set cells 1 and 5 to 32 (end on 0)
>[-<+>]            move 1 back to 0 (end on 1) 

,[                 loop over input (cell 1) 
    
    copy cell 0 to cell 2
    <[->>+>+<<<]     [move cell 0 to cells 2 and 3 (end on 0)]
    >>>[-<<<+>>>]    [move cell 3 back to cell 0 (end on 3)] 
    
    copy cell 1 to cell 3
    <<[->>+>+<<<]    [move cell 1 to cells 3 and 4 (end on 1)]
    >>>[-<<<+>>>]    [move cell 4 back to cell 1 (end on 4)] 
    
    <<[->-<]         [subtract cell 2 from cell 3 (end on 2)] 
    
    >                cell 3 / input minus ' ' 
    
    >+<              set cell 4 as flag to run space code if set (end on 3) 
    
    [                not space branch (check if in lowercase zone)
        >-                 clear cell 4 (end on 4) 
        
        >>>+[+[<]>>+<+]>   set cell 9 to 65 (='a' minus ' ') (uses 6 7 8 as tmp) (end on 9) 
        
        [-<<<<<<->>>>>>]   [subtract cell 9 from cell 3 (end on 9)] 
        
        [need to check if cell 3 is from 0-26, it could be above and not a lowercase letter] 
        
        <<<                cell 6
        +++++[>+++++<-]>+  set cell 7 to 26
        >>+<<              set cell 9 to 1 (end on 7) 
        
        [                  do 26 times 
            
            <<<<                   cell 3
            [->+>>+<<<]            [move cell 3 to cell 4 and 6 (end on 3)]
            >[-<+>]                [move cell 4 back to cell 3 (end on 4)] 
            
            >>                     cell 6 
            
            [[-]>>+<<]             [if cell 6 is set, set cell 8 to 1 (end on 6)] 
            
            >>-                    decrement cell 8 (if cell 3 was not zero cell 8 is now zero) (if cell 3 was zero cell 8 is now 255) 
            
            [                      if cell 3 is zero (start here on 8)
                <<<                    cell 5
                [-<<<<->>>>]           [sub cell 5 from cell 1 (end on 5)] 
                
                >>>+                   clear cell 8 (end on 8)
                >-<                    set cell 9 to 0 (end on 8)
            ] 
            
            <<<<<-                 decrement cell 3 (end on 3)
            >>>>-                  end on 7 and decrement
        ] 
        
        >>[                cell 9 set (else branch so we have no lowercase letter)
            -                  [clear cell 9] 
            
            <<<<               cell 5
            [-]                [clear cell 5]
            >>>>               cell 9
        ] 
        
        <<<<<<             cell 3
        [-]                [clear cell 3]
    ] 
    
    >                cell 4
    [                space branch
        -                      clear cell 4 (end on 4)
        
        >[-]                   clear cell 5 (space flag/may have been set)
        <<<<<[->>>+>>+<<<<<]   [set space flag (cell 5) (coincidentally, it is also 32 so we can copy from cell 0) (0-> 5 and 3) (end on 0)]
        >>>[-<<<+>>>]          [3 to 0 (end on 3)] 
        
        >                      end on 4
    ] 
    
    <<<.             from 4 to 1 (output 1)
,]

C - 85 Bytes

s[99]={32};j;main(i){for(;read(0,&j,1);)putchar(s[i++]=j<97|j>122|s[i-1]-32?j:j-32);}

Thanks to @ceilingcat because I saved 43 bytes with his modification.

Ungolfed

s[99] = {32};
j;

main(i)
{
   for( ; read(0, &j, 1); )
         
   putchar(s[i++] = j < 97 | j > 122 | s[i - 1] - 32 ?j :j - 32);
}

Explanation

A simple program that reads characters from the console and capitalizes each "valid" word and then displays it on the console as well. It was tested in GCC and it generates some warnings.

Factor, 57 bytes

readln >words [ unclip ch>upper prefix ] map ""join write

Try it online!

Factor has a capitalize word, but for some reason it lowercases the rest of the word, so I couldn't use it.

Ly, 33 bytes

irs[:'`Gf'zG!fpl**[p' -0]p' =spo]

Try it online!

Pretty much a straight-forward application of the rules this time...

irs                               - read input, reverse, stash non-zero "capitalize?" state
   [                            ] - for each codepoint in the input...
    :                             - duplicate current char
     '`G                          - is it >="a"?
        f                         - pull current char forward
         'zG!                     - is it <="z"?
             fp                   - pull current char forward, delete it
               l                  - load "capitalize?" flag
                **                - multiply all three tests values
                  [p   0]p        - if/then, true if we need to capitalize
                    ' -           - sub 32 from codepoint to capitalize
                          ' =     - is the current char a space?
                             s    - save result as "capitalize?" flag
                              p   - delete test result
                               o  - print current codepoint as a char

Japt -S, 7 bytes

¸®©hZÎu

Try it

¸®©hZÎu     :Implicit input of string
¸           :Split on spaces
 ®          :Map each Z
  ©         :  Logical AND with
   h        :  Replace first character with
    ZÎ      :    First character of Z
      u     :    Uppercased
            :Implicit output joined with spaces

Vyxal s, 7 bytes

ðẆƛḣ$⇧p

Try it Online!

Fixed thanks to lyxal.

ðẆƛ     # Over each word...
   ḣ$ p # To the first character...
     ⇧  # Uppercase it

Python 3, 59 bytes

print(*(w[0].upper()+w[1:]for w in input().split(' ')if w))

Try it online!

Lexurgy, 116 bytes

Simple replacement of lowercase letters at the beginning of a word to uppercase.

This works because of how Lexurgy handles whitespace in the input. The $ symbol denotes a word boundary, which is defined as any sort of whitespace before or after any character. As a result, input like hello world on a single line is considered as 2 words rather than 1 word.

a:
{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}=>{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}/$ _

JavaScript, 59 bytes

n=>n.split` `.map(e=>e[0].toUpperCase()+e.slice(1)).join` `

As I mentioned in some of my other answers, my solutions tend to be extremely boring and unimaginative.

05AB1E, 8 bytes

#εćuì}ðý

Try it online.

Explanation:"

#         # Split the (implicit) input-string by the space character
          # (multiple adjacent spaces will give empty items in the list)
 ε        # Map each string to:
  ć       #  Extract the head; pop and push the remainder and head separately to the stack
   u      #  Uppercase the head
    ì     #  Prepend it in front of the remainder again
     }ðý  # After the map: join by spaces (which is output implicitly as result)

Java 8, 135 bytes

It's rare that I beat all the other answers that use the same language.

interface M{static void main(String[]a){int c=0;for(char i:a[0].toCharArray()){System.out.print(c==0?(i+"").toUpperCase():i);c=i-32;}}}

TIO

Brachylog, 12 bytes

ṇ₁{ụʰ|}ᵐ~ṇ₁w

Try it online!

           w    Print
                the input
ṇ₁              split on spaces
  {   }ᵐ        with every word
    ʰ           having its first letter
   ụ            uppercased
     |          (without failing on empty words)
        ~ṇ₁     and then joined by spaces.

If this was allowed to be a function which would normalize runs of spaces to just one space, it would only be two bytes shorter: ṇ₁{ụʰ}ˢ~ṇ₁. That would be another two bytes shorter if we'd figured out how to parse chained metapredicates (ṇ₁ụʰˢ~ṇ₁), but since handling runs of spaces requires the |, it doesn't actually matter for this challenge.

VTL-2, 89 bytes

1 B=A
2 A=$
3 A=A-(32*(((B=0)+(B=32))*(A>97)*(A<123
4 $=8*(1-(A=4
5 $=B
6 #=1-(A=4

If I read the challenge right, input seems fairly flexible, so... This operates every time a character is input. Input is terminated by an EOT (CtrlD). Output is one character behind, so every time you input a character, the previous one will be output. This really confused my brain when I was entering the test case.

Line 1 is fairly obvious, it copies the value of B into A. It's fine to start the program from here because uninitialized variables are assumed to be 0. Line 2 takes a single character input from the terminal and assigns A to its ASCII value. Fairly straightforward so far. Line 3 is a bit of a doozy, but it translates to (keeping in mind that B is the previous character entered, and A is the character just entered) IF (B==NULL OR B==" ") AND (96 < A < 123) THEN A=A-32. Because $ echoes, line 4 inserts a backspace character so long as A isn't EOT. Line 5 prints B, and line 6 is akin to IF A!=EOT THEN GOTO 1.

Perl 6, 35 bytes

say slurp.split(" ")>>.tc.join(" ")

Try it online!

JavaScript, (ES6 RegEx Replacer) 66 bytes

alert(prompt().replace(/(^[A-Z])|(\s[A-Z])/gi,m=>m.toUpperCase()))

V, 5 (non-competing)

$òBvU

Try it online!

Not too interesting. Just a direct port of my vim answer:

$        #Move to the last character
 ò       #Recursively
  B      #Move back a WORD
   vU    #Capitalize

s-lang, 8 bytes + 30 = 38

c![[^ ]*

s-lang

Procedure:

GNU sed, 20 + 1 (-r flag) +30 (regex penalty) = 51

s/(^| +)(.)/\1\u\2/g

(thks @manatwork for helping me save 4 bytes)

Usage :

sed 's/\(^\| \)\(.\)/\1\u\2/g' <<< "eCommerce and eBusiness are cool, don't you agree, Richard III?"

Vim, 11, 10 bytes

qqvUW@qq@q

Explanation:

qq           #Start recording in register 'q'
  vU        #Make the character under the cursor uppercase
     W       #Move forward a WORD
      @q     #recursively call macro 'q'
        q    #stop recording
         @q  #Call the recursive macro

Do I get a gold-badge for outgolfing Dennis?

Java, 167 bytes

public class G{public static void main(String[]e){for(String n:e[0].split(" ")){System.out.print(n.length()<1?"":n.substring(0,1).toUpperCase()+n.substring(1)+" ");}}}

Ungolfed:

public class G {
    public static void main(String[] e) {
        for (String n: e[0].split(" ")) {
            System.out.print(n.length() < 1 ? "" : n.substring(0, 1).toUpperCase() + n.substring(1) + " ");
        }
    }
}

JavaScript (SpiderMonkey 31 (1.8)) 63 70

// first version
// alert([for(c of x=prompt())[x?c.toUpperCase():c,x=c<'!'][0]].join(''))
// new version, thx @nderscore
[for(c of prompt(o=x=''))o+=x=x<'!'?c.toUpperCase():c],alert(o)

KDB(Q), 30 bytes

{@[x;0,1+where" "=-1_x;upper]}

Explanation

                  -1_x            / handle case where last char is space
       1+where" "=                / find index of space and shift by 1
     0,                           / include the first char
 @[x;                 ;upper]     / apply upper case
{                            }    / lambda

Test

q){@[x;0,1+where" "=-1_x;upper]}t
"ECommerce Rocks. CrazyCamelCase Stuff. _those  Pigeon-toed Shennanigans. Fiery Trailblazing 345 Thirty-two Roger. The Quick Brown Fox Jumped Over The Lazy Dogs. Clancy Brown Would Have Been Cool As Lex Luthor. Good_bye"

R, 96 93

A different approach than Alex A's. I'm not using a loop, rather creating a another vector with a space prepended, then uppercasing any character in the original vector that is sitting under a space.

p=(strsplit(readline(),''))[[1]];s=c(' ',p);p[e]=toupper(p[e<-s==' ']);cat(head(p,-1),sep='')

Doesn't beat the regexp version though.

Edit I love it when you learn something new. Replace p[-length(p)] with head(p,-1)

Rebol - 56 51

print map-each n split input" "[uppercase/part n 1]

The above works correctly with the test case and also with multiple whitespace input.

An interesting (but longer!) alternative version would to use the parse dialect (not a regex!) which when golfed would come down to 65 chars:

parse s: input [any [x: thru [" " | end] (uppercase/part x 1)]] print s

Groovy - 69

t=args[0];t.eachWithIndex{c,i->print!i|t[i-1]==' '?c.toUpperCase():c}

C# Linq - 187

This is nowhere close to winning but I just love Linq too much.

namespace System{using Linq;class P{static void Main(string[]a){Console.Write(a[0].Substring(1).Aggregate(a[0][0].ToString().ToUpper(),(b,c)=>b[b.Length-1]==32?b+char.ToUpper(c):b+c));}}}

C, 74 bytes

a,b=1;main(){while((a=getchar())>0)b=isspace(putchar(b?toupper(a):a));}

Makes no assumptions about the run-time character set (ASCII, EBCDIC, Baudot, ...whatever). Does assume that EOF is negative (I think C guarantees that).

a,b=1;
main()
{
    while((a=getchar())>0)
        b=isspace(putchar(b?toupper(a):a));
}

a is the input character; b is true if the last character was space. The only non-obvious bit is that we use the fact that putchar returns the character printed if there's no error.

Ruby(55)

gets.chars.inject(' '){|c,d|print c<?!?d.upcase():d;d}

I know that a better ruby solution exits in an old answer, but I like this better.

note:c<?! checks for chars that come before !, which are just control/whitespace.

Java, 142

First post here as well, but found that the requirements are a one to one mapping to the way Java handles arguments.

class X{public static void main(String[]s){for(String p:s){System.out.append(p.toUpperCase().charAt(0)).append(p,1,p.length()).append(' ');}}}

Unfortunately, because they are command line arguments, spaces are not preserved, and the offending words (don't) have to be quoted ("don't"). So while I didn't entirely meet all the criteria I just wanted to share a Java solution that's under 200 bytes.

Python 3, 101 bytes

x=list(' '+input())
for i in range(len(x)-1):
 if x[i-1]==' ':x[i]=x[i].title()
print(''.join(x[1:]))

Python 3, 58 63 59 chars

print(*(c and c[0].upper()+c[1:] for c in input().split(" ")))

I have to add 5 characters because of bugfix

PHP: 76 74 characters

foreach($l=str_split(fgets(STDIN))as$c){echo$l?ucfirst($c):$c;$l=$c==" ";}

Sample run:

bash-4.3$ php -r 'foreach($l=str_split(fgets(STDIN))as$c){echo$l?ucfirst($c):$c;$l=$c==" ";}' <<< 'eCommerce rocks. crazyCamelCase stuff. _those  pigeon-toed shennanigans. Fiery trailblazing 345 thirty-two Roger. The quick brown fox jumped over the lazy dogs. Clancy Brown would have been cool as Lex Luthor. good_bye'
ECommerce Rocks. CrazyCamelCase Stuff. _those  Pigeon-toed Shennanigans. Fiery Trailblazing 345 Thirty-two Roger. The Quick Brown Fox Jumped Over The Lazy Dogs. Clancy Brown Would Have Been Cool As Lex Luthor. Good_bye

Perl Version < 5.18, 30 27 26 25

say map"\u$_",split$,=$"

24 characters +1 for -n.

\u makes the next character in a string uppercase. @ThisSuitIsBlackNot pointed this out to save 1 byte. Before we were using the function ucfirst.

From the perldocs,

As another special case, split emulates the default behavior of the command line tool awk when the PATTERN is either omitted or a literal string composed of a single space character (such as ' ' or "\x20" , but not e.g. / / ). In this case, any leading whitespace in EXPR is removed before splitting occurs, and the PATTERN is instead treated as if it were /\s+/ ; in particular, this means that any contiguous whitespace (not just a single space character) is used as a separator. However, this special treatment can be avoided by specifying the pattern / / instead of the string " " , thereby allowing only a single space character to be a separator. In earlier Perls this special case was restricted to the use of a plain " " as the pattern argument to split, in Perl 5.18.0 and later this special case is triggered by any expression which evaluates as the simple string " " .

Since $" evaluates to a space, this will preserve the spaces. Since we want to both set $, to a space character, and input a space character to the split, @nutki pointed out we can do both as the input to the split. That saves 3 bytes from what we had before, which was first setting $, and then inputting $" to the split.

Using a , for map instead of {} saves an additional byte, as @alexander-brett pointed out.

Run with:

echo 'eCommerce     rocks. crazyCamelCase stuff. _those  pigeon-toed shennanigans. Fiery trailblazing 345 thirty-two Roger. The quick brown fox jumped over the lazy dogs. Clancy Brown would have been cool as Lex Luthor. good_bye' | perl -nE'say map"\u$_",split$,=$"'

Python 2, 64 59 63

Try it here

This iterates through each word, converting the first character of each to uppercase, then printing it with a space after. I have to check if the split substring is not empty, which refers to multiple spaces in a row.

for w in raw_input().split(" "):print w and w[0].upper()+w[1:],

C#, 143 138123 bytes

class G{static void Main(string[]a){var l=' ';foreach(var c in a[0]){System.Console.Write(l==' '?char.ToUpper(c):c);l=c;}}}

Runs as a command line util. Will try and golf it down from here. Comments & critique encouraged!

Java, 201 178 174 bytes

class C{public static void main(String[]a){for(String s:a[0].split(" ")){int c=s.length()>0?s.charAt(0):0;System.out.print((c>96&c<123?(char)(c-32)+s.substring(1):s)+" ");}}}

I'm back after realizing that my previous program did not preserve spaces.

First time I've had to submit an entire class before. Pass in the string as a command-line argument wrapped in quotes. (I never thought I could get it this short!)

Haskell, 69

import Data.Char
main=interact$tail.scanl(!)' '
' '!c=toUpper c;_!c=c

Explanation:

scanl takes a function (a -> b -> a) and an initial value a, then iterates over a list of [b]s to make a list of [a]s:

scanl (!) z [a,b,c] == [   z
                       ,   z ! a
                       ,  (z ! a) ! b
                       , ((z ! a) ! b) ! c]

It repeatedly takes the previous result as the left argument of the function passed to it, and a value from the input list as the right argument, to make the next one.

I wrote a function (!) :: Char -> Char -> Char that returns the right character you pass it, but capitalizes it if the left char is ' ' (space). For scanl, this means: return the value from the input list, but capitalize it if the previous result was a space. So scanl (!) ' ' "ab cd" becomes:

    scanl (!) ' ' "ab cd"
==> ' ' : scanl (!) (' ' ! 'a') "b cd"
==> ' ' : scanl (!)     'A'     "b cd"
==> ' ' : 'A' : scanl (!) ('A' ! 'b') " cd"
==> ' ' : 'A' : scanl (!)     'b'     " cd"
==> ' ' : 'A' : 'b' : scanl (!) ('b' ! ' ') "cd"
==> ' ' : 'A' : 'b' : scanl (!)     ' '     "cd"
==> ' ' : 'A' : 'b' : ' ' : scanl (!) (' ' ! 'c') "d"
==> ' ' : 'A' : 'b' : ' ' : scanl (!)     'C'     "d"
==> ' ' : 'A' : 'b' : ' ' : 'C' : scanl (!) ('C' ! 'd') ""
==> ' ' : 'A' : 'b' : ' ' : 'C' : scanl (!)     'd'     ""
==> ' ' : 'A' : 'b' : ' ' : 'C' : 'd' : ""
==> " Ab Cd"

We need the initial value ' ' to capitalize the first letter, but then we chop it off with tail to get our final result.

JAVA, 204 211 226 bytes

My first entry on CG, I hope it's fine:

class U{public static void main(String[]s){int i=0;char[]r=s[0].toCharArray();r[0]=Character.toUpperCase(r[0]);for(char c:r){if(c==' '&&i>0)r[i+1]=Character.toUpperCase(r[i+1]);i++;System.out.print(c);}}}

Saved 7 bytes thanks to @TNT

JavaScript (regex solution) - 104 bytes

Someone has to bite the bullet and post the RegEx solution! 74 characters, plus the +30 character penalty:

alert(prompt().replace(/(^| )[a-z]/g,function(m){return m.toUpperCase()}))

Or if you want to read and understand the code in its non-compacted fashion:

//     Matches the (beginning of the line or a space), followed by a lowercase English character.  
string.replace( /(^| )[a-z]/g ,
                function(match) { return match.toUpperCase(); }

Lua, 64 62 61 bytes

Lua is a horrendous language to golf in, so I'm pretty proud of myself for this one.

print(string.gsub(" "..io.read(),"%s%l",string.upper):sub(2))

[Try it here]1 Outdated, will update tommorow

JAVA, 273 bytes

EDIT

import static java.lang.System.*;class x{public static void main(String[] s){char[] a=new java.util.Scanner(in).nextLine().toCharArray();boolean f=1>0;for(int i=0;i<a.length;i++){if(a[i]==' '){f=1>0;continue;}if(f){a[i]=Character.toUpperCase(a[i]);f=1<0;}}out.println(a);}}

Python 3, 59 56 bytes

f=1
for c in input():print(end=f*c.upper()or c);f=c==" "

Thanks to @Reticality for 3 bytes.

Perl, 13 bytes

perl -040pe '$_="\u$_"'

9 bytes plus 4 bytes for 040p (assuming I've interpreted the rules on special invocations correctly).

-040 sets the input record separator $/ to a single space, so spaces are preserved; the \u escape sequence converts the next character to title case.

PHP 64 76 77 83 84 89 bytes

Does $_GET count as input in PHP?
If so, here is my first CG attempt

foreach(explode(' ',$_GET[@s])as$k=>$v)echo$k?' ':'',ucfirst($v)

Thanks manatwork :)

One could just use the ucwords function, which would result in 21 bytes:

<?=ucwords($_GET[@s])

thanks Harry Mustoe-Playfair :)

R, 139 105 bytes

for(i in 1:length(p<-strsplit(readline(),"")[[1]])){if(i<2||p[i-1]==" ")p[i]=toupper(p[i])};cat(p,sep="")

Ungolfed + explanation:

# Assign p to be a vector of the input read from stdin, split into characters

for(i in 1:length(p <- strsplit(readline(), "")[[1]])) {

    # If we're at the first iteration or the previous character was a space

    if (i < 2 || p[i-1] == " ") {

        # Convert the current character to its uppercase equivalent

        p[i] <- toupper(p[i])
    }
}

# Join the vector elements into a single string and print it to stdout
cat(p, sep = "")

R with regex, 49 41 + 30 = 71 bytes

I'm really bummed; this actually has a better score using regular expressions with the penalty.

gsub("(^.| +.)","\\U\\1",readline(),pe=T)

This matches any single character at the beginning of the string or following any number of spaces and replaces it with an uppercase version of the capture. Note that applying \\U is legit and has no effect for non-letters. pe=T is interpreted as perl = TRUE since it takes advantage of R's partial matching of function parameters and the synonym for TRUE. For whatever reason, R doesn't use Perl-style regular expression by default.

Thanks to MickyT for helping save 8 bytes on the regex approach!

Mathematica, 66 bytes

Print@StringReplace[InputString[],WordBoundary~~a_:>ToUpperCase@a]

I would use ToCamelCase, but it doesn't preserve spacing.

C#, 133 131

using C=System.Console;class P{static void Main(){var s=2>1;foreach(var c in C.ReadLine()){C.Write(s?char.ToUpper(c):c);s=c==32;}}}

CSS 2.1, 49

:after{content:attr(t);text-transform:capitalize}

Explanation:

Runnable snippet:

:after {
    content: attr(t);
    text-transform: capitalize;
}
<div t="eCommerce rocks. crazyCamelCase stuff. _those  pigeon-toed shennanigans. Fiery trailblazing 345 thirty-two Roger. The quick brown fox jumped over the lazy dogs. Clancy Brown would have been cool as Lex Luthor. good_bye"></div>

Note: CSS 2.1 specified the desired behavior: capitalize uppercased the first character of each word. However, CSS3 uppercases first typographic letter unit of each word. So the snippet above won't work properly neither on old IE, which didn't follow CSS 2.1; nor on new compliant browsers which follow CSS3.

CJam, 14 bytes

It's not the shortest, but...

qS/Sf.{\eu}s1>

Another answer using similar ideas:

qS/Laf.{;eu}S*

.x only changes the first item if one of the parameters has only one item.

C, 64 63 bytes

a;main(c){while(~(c=getchar()))putchar(a?c:toupper(c)),a=c-32;}

Fix: some compilers (such as Clang) don't like an int parameters in place of argv, so I moved it to a global variable. The byte count stays the same. Thanks to squeamish ossifrage for noticing. Down to 63 bytes, thanks Dennis.

Ungolfed:

int a;

int main(int c) {
    while(~(c = getchar()))
        putchar(a ? c : toupper(c)),
        a = c - ' ';
}

Pretty straightforward: if a is false, the character is converted to uppercase. It is set after reading a space: c - ' ' is false only if c == ' '. toupper() ignores everything that is not a lowercase letter, so symbols and multiple spaces are fine. -1 has all bits set, so when getchar() returns -1 the NOT operator makes it zero, and the loop stops. a is declared as a global variable, so it is initializd to zero (false). This ensures that the first word is capitalized.

PHP, 91+30 bytes

Well, all the ideas were used.

I had to resort to drastic measures and build a huge piece of code:

<?=preg_replace_callback('@( |^)([a-z])@',function($a){return$a[1].($a[2]^' ');},$_GET[s]);

The only function it uses is to fetch the small letters, using regex.

><> (Fish), 39 bytes

</?-' 'o:;?(0:<-*' '*('{'$)'`'::i
i/.0e

Method:

CJam, 15 13 bytes

Lq{_eu?_S-}/;

Try it online in the CJam interpreter.

Pseudocode

L             e# B := ""
 q            e# Q := input()
  {       }/  e# for C in Q:
   _eu?       e#     C := B ? C : uppercase(C)
       _S-    e#     B := string(C).strip(" ")
            ; e# discard(B)

All modified characters C are left on the stack and, therefore, printed when exiting.

PHP, 82

echo join(' ',array_map(function($s){return ucfirst($s);},explode(' ',$argv[1])));

Usage :

$ php code.php "eCommerce rocks. crazyCamelCase stuff. _those  pigeon-toed shennanigans. Fiery trailblazing 345 thirty-two Roger. The quick brown fox jumped over the lazy dogs. Clancy Brown would have been cool as Lex Luthor. good_bye"

Haskell: 127 characters

import Data.List
import Data.Char
i=isSpace
s a b=i a==i b
u (w:ws)=(toUpper w):ws
f w=concatMap u$groupBy s w
main=interact f

Ruby: 46 characters

l=0
gets.chars{|c|l&&c.upcase!
l=c==" "
$><<c}

Sample run:

bash-4.3$ ruby -e 'l=0;gets.chars{|c|l&&c.upcase!;l=c==" ";$><<c}' <<< 'eCommerce rocks. crazyCamelCase stuff. _those  pigeon-toed shennanigans. Fiery trailblazing 345 thirty-two Roger. The quick brown fox jumped over the lazy dogs. Clancy Brown would have been cool as Lex Luthor. good_bye'
ECommerce Rocks. CrazyCamelCase Stuff. _those  Pigeon-toed Shennanigans. Fiery Trailblazing 345 Thirty-two Roger. The Quick Brown Fox Jumped Over The Lazy Dogs. Clancy Brown Would Have Been Cool As Lex Luthor. Good_bye

CJam, 17 15 bytes

lS/{S+(eu\+}/W<

Test it here.

Fairly straightforward implementation of the spec. Make use of the new {}& to avoid errors for consecutive spaces.

Two bytes saved by Dennis.

C, 125

Not the shortest of solutions, but I really like to golf in C.

char b[99];main(c){while(scanf("%[A-Za-z_-]",b)==1)islower(*b)&&(*b&=223),printf("%s",b);~(c=getchar())&&putchar(c)&&main();}

ungolfed:

char b[99];
main(c)
{
  while(scanf("%[A-Za-z_-]", b) == 1) {
    if(islower(b[0])) {
      b[0] &= 0xDF;
    }
    printf("%s", b);
  }
  if((c = getchar()) != -1) {
      putchar(c);
      main();
  }
}

I don't know wheter using regex-like syntax in scanf is streching the rules, but it works quite nicely. (Well, technically it's not a full regex)

An other thing to consider is that this code only works for words shorter than 99 bytes. But I think this solution will work for most cases.

Python 2, 73 bytes

i=raw_input()
print''.join((c,c.upper())[p==' ']for p,c in zip(' '+i,i))

This program capitalises a letter if preceded by a space (with a kludge for the first character in the string). It relies on the .upper() string method to capitalise correctly.

Pip, 15 + 1 for -s = 16

{IaUC:a@0a}Ma^s

Explanation:

                  a is first cmdline arg (implicit)
            a^s   Split a on spaces
{         }M      Map this function to each element:
 Ia                 If the word is not empty,
   UC:a@0             uppercase its first character
         a          Return the word
                  Output the resulting list (implicit) joined on spaces (-s flag)

One interesting feature of Pip that this program draws on is the : assignment meta-operator. Most C-like languages have some set of compute-and-assign operators: e.g. x*=5 does the same thing as x=x*5. In Pip, however, you can tack : onto any operator and turn it into a compute-and-assign operator. This even goes for unary operators. So -:x computes -x and assigns it back to x, the same as x:-x would. In this case, UC: is used (together with Pip's mutable strings) to uppercase the first character of a word.

The program takes input from the command-line, requiring an invocation like this:

python3 pip.py -se "{IaUC:a@0a}Ma^s" "test teSt TEST  _test"

Bash, 61

a="${@//: / }"
a=(${a//: / })
a="${a[@]^}"
echo "${a//:/ }"

Note the colons are simply to make the program display OK here. In reality these can be some non-printable character, such as BEL.

Output

$ ./cap1st.sh "eCommerce rocks. crazyCamelCase stuff. _those  pigeon-toed shennanigans. Fiery trailblazing 345 thirty-two Roger. The quick brown fox jumped over the lazy dogs. Clancy Brown would have been cool as Lex Luthor. good_bye"
ECommerce Rocks. CrazyCamelCase Stuff. _those  Pigeon-toed Shennanigans. Fiery Trailblazing 345 Thirty-two Roger. The Quick Brown Fox Jumped Over The Lazy Dogs. Clancy Brown Would Have Been Cool As Lex Luthor. Good_bye
$ 

Bash, 12

Sadly this one doesn't preserve leading/mutliple/trailing spaces, but otherwise it works:

echo "${@^}"

Output

$ ./cap1st.sh eCommerce rocks. crazyCamelCase stuff. _those  pigeon-toed shennanigans. Fiery trailblazing 345 thirty-two Roger. The quick brown fox jumped over the lazy dogs. Clancy Brown would have been cool as Lex Luthor. good_bye
ECommerce Rocks. CrazyCamelCase Stuff. _those Pigeon-toed Shennanigans. Fiery Trailblazing 345 Thirty-two Roger. The Quick Brown Fox Jumped Over The Lazy Dogs. Clancy Brown Would Have Been Cool As Lex Luthor. Good_bye
$ 

Javascript (ES6), 77 bytes

alert(prompt().split(' ').map(x=>x&&x[0].toUpperCase()+x.slice(1)).join(' '))

Commented

alert( // output
    prompt(). // take input
    split(' '). // split by spaces
    map(x=> // map function to array
        x && // if x, empty string "" is falsey and returns itself
        x[0].toUpperCase() + x.slice(1) // capaitalize 1st char and concatenate the rest
    ).
    join(' ') // join array with spaces
)

Pyth, 20 bytes

uXGHr@GH1fqd@+dzTUzz

These multiple spaces really sucks. Otherwise there would have been a really easy 12 bytes solution.

Try it online: Pyth Compiler/Executor

Explanation

                      implicit: z = input string
         f       Uz   filter [0, 1, 2, ..., len(z)-1] for elements T, which satisfy:
          qd@+dzT        " " == (" " + z)[T]
                      (this finds all indices, which should be capitalized)
u                  z  reduce, start with G = z, for H in idices ^ update G by
 XGH                     replace the Hth char of G by
    r   1                upper-case of
     @GH                 G[H]
                      implicitly print result

edit: 16 chars is possible with @Dennis algorithm.