Don't panic; this is par for the course in remodeling. Unless absolutely necessary, you don't want to rip out the entire stud or joist. Doing so may cause more problems with surrounding structural elements. Instead, sister it.
Sistering is the process of repairing a deteriorated stud or joist by nailing, screwing, or bolting a "like" piece of material next to it. Correct the cracked or rotten wall stud by nailing another stud alongside it. Joists will need another piece of joist-like material (in older homes, usually a 2"x8" or 2"x10" piece of wood) and should be attached with heavy nails or even bolts.
The new piece of material does not have to be as long as the deteriorated section. But of course--the longer, the better. At least, make sure it extends well beyond the deteriorated area--in both directions. Be sure the deteriorated stud or joist has enough solid material to which you can attach the new material.
Important Note: Also, make certain that this sistering job is not symptomatic of some larger problem--termites, water incursion, pervasive rotting wood, etc. You don't want to be putting a Band-Aid on the problem.

