The reason it stops counting is because scanf reads one word at a time. It's reading the first word and then halting, ignoring the rest of the line.
Instead, use fgets:
Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the end-of-file is reached, whichever happens first.
You can read from standard input like so:
fgets(phrase, 256, stdin);
Have you considered using strlen to measure the length of your input?
Finally, you should get into the habit of initialising variables when you declare them:
int i = 0,j = 0, size = 0;
When a variable is declared its value is 'whatever was in memory', until you set its value. In your example 'length' is never initialised, which will lead to unexpected behaviour. Initialising variables is a good way to avoid unexpected behaviour and time wasted tracking down bugs.