Of course code snippets should work, but you shouldn't ever assume that they do, especially when you get them from some random place on the internet. Who knows who is putting these code snippets out there. Even pieces of code from professionals in programming books can have errors. They can also go out of date without being updated.

The real point of a snippet of code is usually to show you an example. It is best if that example actually works, but you can still learn a lot from them if they don't.

I don't know what "dreaming in c" is, so I can't comment on the particular place you found this code, but in general don't be surprised if you find things on the internet that aren't quite right.