The general outline is to write your given compact metric space $A$ as a decomposition into two sets, then four sets, then eight sets, etc., in the exact same fashion that the Cantor set is decomposed, except that whereas the decomposition elements of the Cantor set are pairwise disjoint, the decomposition elements in $A$ need not be pairwise disjoint. Be careful about how your decomposition elements are indexed. Once similarly indexed decomposition elements of $C$ and of $A$ are put side-by-side, the formula for writing the desired function $C \mapsto A$ is evident.
Here's a few details.
For any compact metric space $A$, you can write it as a union of two compact subsets
$$A = A_0 \cup A_1
$$
and then for each $i_1 \in \{0,1\}$ you can write $A_{i_1}$ as a union of two compact subsets
$$A_{i_1} = A_{i_1,0} \cup A_{i_1,1}
$$
and then for each $i_1,i_2 \in \{0,1\}$ you can write $A_{i_1,i_2}$ as a union of two compact subsets
$$A_{i_1,i_2} = A_{i_1,i_2,0} \cup A_{i_1,i_2,1}
$$
and so on and so on inductively, so that as the length of the subscript sequence increases, the diameter of the set decreases to zero. It follows for any infinite sequence $\omega = (i_1,i_2,i_3,...)$ of $0$'s and $1$'s the nested decreasing intersection
$$A_\omega = A_{i_1} \cap A_{i_1, i_2} \cap A_{i_1, i_2, i_3} \cap \cdots
$$
is a single point.
Then you take the usual description of the Cantor set $C$ as the set of real numbers $x$ written in trinary as
$$x = .j_1 j_2 j_3 \cdots
$$
where $j_n \in \{0,2\}$, let $i_n = j_n/2 \in \{0,1\}$, let $\omega(x) = (i_1,i_2,i_3,...)$, and map $x$ to the point $A_{\omega(x)}$.