Step 1: Multiply by the conjugate:
Multiply the top and the bottom by $1 - \cos x$. The bottom becomes $(1+\cos x)(1-\cos x) = 1 - \cos^2 x = \sin^2 x$.
\[ \int \frac{dx}{1+\cos x} = \int \frac{1-\cos x}{\sin^2 x}\,dx. \]
Step 2: Split into two standard integrals:
Write the fraction as two terms:
\[ \int \frac{1}{\sin^2 x}\,dx - \int \frac{\cos x}{\sin^2 x}\,dx = \int \operatorname{cosec}^2 x\,dx - \int \operatorname{cosec}x\cot x\,dx. \]
Step 3: Integrate each term:
We know $\int \operatorname{cosec}^2 x\,dx = -\cot x$ and $\int \operatorname{cosec}x\cot x\,dx = -\operatorname{cosec}x$. So
\[ -\cot x + \operatorname{cosec}x + C = \frac{1-\cos x}{\sin x} + C. \]
Step 4: Simplify using half angles:
Use $1 - \cos x = 2\sin^2\tfrac{x}{2}$ and $\sin x = 2\sin\tfrac{x}{2}\cos\tfrac{x}{2}$:
\[ \frac{1-\cos x}{\sin x} = \frac{2\sin^2\frac{x}{2}}{2\sin\frac{x}{2}\cos\frac{x}{2}} = \tan\frac{x}{2}. \]
Final Answer:
Both methods give the same result:
\[ \boxed{\tan\frac{x}{2} + C} \]