THE PETTING AND BITING SYNDROME

Petting is very enjoyable to humans but less enjoyable to cats. It relaxes us, but it stresses up some cats. If a previously friendly cat suddenly starts biting or scratching, take it to a vet to make sure that it does not have some injury. It may be a hidden abcess etc. which means your touch is painful.
There is also the Petting and Biting Syndrome, when the cat responds to petting with aggression. This is a cat who is in conflict it wants attention but it fears it too. The cat may want contact and love, but after a certain time it gets frightened. At this point it bites or scratches suddenly.
This may be the result of a wild kittenhood and probably this kind of cat's desire for space should be respected. Some stray cats, however, have had kittenhoods in a home but then have suffered at the hands of man while they lived in the street. These cats, after months in a safe new home, may accept petting more easily. But never, never hurry them.
Some cats have sensitive areas -- tummy and hind parts -- which produce aggression. Avoid these! Long haired cats may have been roughly groomed in the past and be extra likely to bite or scratch if they feel threatened. (They must be groomed and I can send details).
If you want to try to change this behaviour, only pet when the cat is in a position from which it can get away -- ie with no enclosed arms and probably not on a lap. Do not pick it up. Try stroking only the head and down the back. Always let the cat remove itself when it has had enough. If you are patient, the cat may learn to tolerate slightly longer sessions of petting
Develop your relationship in other ways, not just petting. Non-cuddely cats will enjoy play. Have regular play sessions with string, fishing rods etc. The other way to develop a relationship is to use food treats to train a cat to do simple tricks. Greedy cats really enjoy these and will actually solicit training sessions! Less greedy cats probably won't bother to do it. To train a cat to do tricks requires endless patience, no punishment whatsoever, no forcing (ie putting into position). A lot of things you can do with dogs, will simply mean a cat leaves the room!