For which values of $c$ is the function $f(x)$ in $W^{1,p}_{\mathrm{loc}} (\mathbb{R})$? We're given the function  
$$f(x) = \begin{cases}     2 \sin(x) + 3, & x> 0 \\
      -2 \sin(x) + c, & x \leq 0 
   \end{cases} \\$$
and asked to find the values of $c$ for which $f \in W^{1,p}_{\mathrm{loc}}$. 
To start, I've found the distributional derivative of $f$ to be 
$$f'(x) = \begin{cases}     2 \cos(x), & x> 0 \\
      -2 \cos(x), & x \leq 0 
   \end{cases} \\$$
and I want to find values of $c$ for which $\left\lVert f\right\rVert_{L^p(K)} < \infty$ where $K$ is any closed ball in $\mathbb{R}$. But I'm stuck on that computation. 
 A: Your claimed distributional derivative is not correct in general. Indeed you may pick up a extra Dirac delta term arising from the fact that, 
$$\frac{\mathrm{d}}{\mathrm{d}t}\, 1_{(-\infty,0]} = \delta_0.$$
The following rules out all but possibly one value of $c.$

Claim: If $f \in W^{1,p}_{\mathrm{loc}}(\mathbb R) \subset W^{1,1}_{\mathrm{loc}}(\mathbb R),$ then $f$ is continuous (more precisely it admits a continuous representative).

Proof of claim: Note that if $g \in C^{\infty}_c(\mathbb R),$ then by the fundamental theorem of calculus and $a < x < b,$
\begin{align*}
    |g(x)| &= \left|g(a)+\int_{a}^x g'(t) \,\mathrm{d}t \right| \\
    &\leq \frac1{b-a}\lVert g \rVert_{L^1([a,b])} + \frac1{b-a}\int_a^b |g(a)-g(x)|\,\mathrm{d}t + \lVert g' \rVert_{L^1((a,b))} \\
    &\leq C_{a,b} \lVert g \rVert_{W^{1,1}([a,b])}.
\end{align*}
So $\lVert g \rVert_{L^{\infty}([a,b])} \leq C \lVert g \rVert_{W^{1,1}([a,b])}$ for all $g \in C^{\infty}([a,b])$ and $[a,b] \subset \mathbb R.$ By approximating $f$ in $W^{1,1}(\mathbb R)$ via mollification, we get a sequence of smooth functions which converges locally uniformly to $f$ by the above estimate. Hence $f$ is continuous in $\mathbb R.$ $\square$
Now your $f$ as defined is continuous if and only if $c=3.$ So we get $f \not \in W^{1,p}_{\mathrm{loc}}(\mathbb R)$ if $c \neq 3.$

Now what happens if $c=3$? We first need to show that $f'$ is what you claim, so let
$$g(x) = \begin{cases}     2 \cos(x) &\text{if } x> 0 \\
      -2 \cos(x) &\text{if } x \leq 0
   \end{cases} \\$$
be the candidate for $f'$ and fix an arbitrary $\varphi \in C^{\infty}_c(\mathbb R).$ Then as $f$ is continuous on $\mathbb R$ and $C^1$ with derivative $g$ on $\mathbb R \setminus \{0\}$, integrating by parts on $(-\infty,0)$ and $(0,\infty)$ we get,
\begin{align*}
  \int_{-\infty}^{\infty} \varphi'(t) f(t) \,\mathrm{d}t &= \int_{-\infty}^0 \varphi'(t) f(t) + \int_0^{\infty} \varphi'(t) f(t)\,\mathrm{d}t \\
   &= \left(\varphi'(0)f(0) - \int_{-\infty}^0 \varphi(t)g(t) \,\mathrm{d}t\right) + \left(-\varphi'(0)f(0) - \int_0^{\infty} \varphi(t)g(t) \,\mathrm{d}t\right) \\
   &= - \int_{-\infty}^{\infty} \varphi(t)g(t).
\end{align*}
Thus $f$ is weakly differentiable with weak derivative $f' = g.$ Note that we needed continuity of $f$ at $0$ to integrate by parts.
Finally as both $f$ and $f'$ are bounded, we get $f, f' \in L^{\infty}(\mathbb R)$ and hence $f,f' \in L^p_{\mathrm{loc}}(\mathbb R)$ for all $p$ by Hölder. Hence $f \in W^{1,p}_{\mathrm{loc}}(\mathbb R)$ for all $1 \leq p \leq \infty$ when $c=3.$
