The best way to protect yourself is to hire an experienced home inspector to check the house's structure and systems, including the roof, heating, plumbing, electrical and air conditioning systems.
The cost of a home inspection ranges between $250 to $500. If you can, have the home inspected after you agree on a price, but before you sign the contract and put down a deposit. If you are in a rush to go to contract to lock in the deal, make sure your contract states that the terms of the purchase are conditioned on the approval of a professional home inspector.
Just because you need to hire a pro, doesn't mean you can't do some checking around yourself before you make an offer. Check for soft spots in the flooring and look for freshly painted patches on the ceiling or walls that could be hiding water damage. Turn electric switches and water faucets on and off. If it's summer, turn off the air conditioning and turn on the heat to make sure it works. Likewise, if it's winter, test out the air conditioning. Tour the basement looking for water on the floor and see if the hot water heater looks rusted or cracked. A little diligence before you start negotiations could save you a lot of time, effort and disappointment.