(a) Shared feature: both are molecules with two ends of differing properties: a long hydrocarbon chain (the hydrophobic tail, which dissolves in oil or grease) and a charged (ionic) end (the hydrophilic head, which stays in water). Because of this both form micelles and clean in the same way.
Difference: in a soap the charged end is the carboxylate group, −COO−Na+ (soaps are sodium or potassium salts of long-chain carboxylic acids). In a detergent the charged end is different: a sulphonate group (sodium salt of a sulphonic acid) or an ammonium group with a chloride or bromide ion.
(b) Cleaning by micelles needs only two things: a long hydrocarbon tail that dissolves in the oil or grease, and an ionic (charged) end that stays in the water. The sign of the charge does not matter for either job. In an ammonium-salt detergent the tail buries itself in the grease exactly as a soap's tail does, and the positively charged heads point outward into the water, so a micelle still forms with the grease trapped inside. Because every micelle has the same kind of charge on its surface, the micelles repel one another and stay dispersed, and the grease is washed away with the water. So a positive head works just as well as the negative carboxylate head of a soap.
(c) The length of the hydrocarbon chain is not what makes a detergent a detergent. Both soaps and detergents already have long chains. The real difference is in the charged end: a carboxylate in soap, a sulphonate or ammonium group in a detergent. A soap with an even longer chain would still have a carboxylate end, would still be precipitated by calcium and magnesium ions as scum, and so would still fail in hard water. It is the different charged end that matters: the carboxylate end of a soap forms an insoluble scum with the calcium and magnesium ions of hard water, so soap is wasted, while the charged ends of detergents do not form insoluble precipitates with these ions, so detergents remain effective in hard water.
