Concept:
The identity
\[
1+\cos x
=
2\cos^2\frac x2
\]
is extremely useful in integrals involving \(1+\cos x\).
Step 1: Evaluate the given integral.
Using
\[
1+\cos x
=
2\cos^2\frac x2,
\]
we obtain
\[
\frac1{1+\cos x}
=
\frac12\sec^2\frac x2.
\]
Hence
\[
\int\frac1{1+\cos x}\,dx
=
\int\frac12\sec^2\frac x2\,dx.
\]
Let
\[
t=\frac x2.
\]
Then
\[
dx=2dt.
\]
Therefore
\[
=
\int\sec^2 t\,dt
=
\tan t+C.
\]
Thus
\[
\tan\frac x2
=
\frac1{f\!\left(\frac x2\right)}.
\]
Step 2: Determine \(f(x)\).
Replacing
\[
\frac x2=t,
\]
we get
\[
\frac1{f(t)}
=
\tan t.
\]
Hence
\[
f(t)
=
\cot t.
\]
Therefore
\[
f(x)=\cot x.
\]
Step 3: Integrate \(f(x)\).
\[
\int f(x)\,dx
=
\int\cot x\,dx.
\]
\[
=
\log|\sin x|+C.
\]
Hence
\[
\boxed{\log|\sin x|+C}.
\]