Lighter, positively charged particles form at the top of the cloud. Heavier, negatively charged particles sink to the bottom of the cloud.When the positive and negative charges grow large enough, a giant spark - lightning - occurs between the two charges within the cloud.
Buildings are fitted with an device known as the lightning conductor. The top point of the lightning conductor has protons and the electrons from the cloud gets attracted to it as they both are unlike charges and the some electrons turn into neutral particles and some go towards the ground. By this no harm is occurred to the house or building.