First of all China and the United States never did fight against one another for centuries. The first time where when United States occupied China was during the 1890's after quelling the Boxer Rebellion. China and the US did became allies during the Second World War while China was divided by warlords and two dominant political parties, the Nationalists and Communist Party.
So what happened?
The Sino-Soviet Split. Ever since Krushschev came into Office, ideas and interpretations over Communism clashed between the Soviets and the Chinese. The Chinese were furious that more aide were given to non-communist nations (India) and equipment used during the Korean War had to be repaid. During the 1960's, the split grew even worst resulting in a border war. Soviet missiles and large divisions were targeted against China given a possibility that Soviet Invasion is very likely. During the 1970's and 80's, in retaliation, China have invaded Vietnam, one of the Soviet Union's closest allies in the Far East.
Why did it happen?
The Cold War was a prime example of the two dominant nations forming strategic blocs and forming military alliances for its own. The enemy of my enemy is a friend. During this period, both the USSR and USA adopted a Neo-realist theory by supporting an Arms Race and establishing better relations with allies and possible allies.
How did it happen?
During the Nixon Administration, secret comminiques between the China and the United States indicated that relations can be opened up again. SoS Henry Kissinger was sent to Beijing secretly during 1971. By 1972, Nixon made an historic visit to China (probably one of the first most important step of dismantling the Soviet Union) therefore normalising relations between China and the United States. The Ping-Pong diplomacy was well famed of re-establishing better ties between the US and China. Afterwards, China adapted to an Open Door policy.
Who was involved?
President Richard Nixon, Secratary of State Henry Kissinger, Chairman Mao Zheng Dong, Premiere Zhou Enlai.
Whew. I had to look back at my Modern China History Paper I've written many years ago.
Sino-American relations are complex therefore both nations are not allies although China does support America's war on Terror and does perform military exercises with the US as well.