Let $\underline{B}$ be a $\tau$-structure and $G\subseteq B$. Suppose $\underline{A}=\langle G\rangle_B$ denote the smallest substructure of $\underline{B}$ generated by $G$.
Show that for each $a\in A$, there exist a $\tau$-term $t(x_1,\ldots,x_n)$ and $g_1,\ldots,g_n\in G$ such that $t^{\underline{B}}(g_1,\ldots,g_n)=a$.
My attempt: Let $$C=\{a\in A\mid \exists \tau\text{-term }t(x_1,\ldots,x_n) \text{ and } g_1,\ldots,g_n\in G :t^{\underline{B}}(g_1,\ldots,g_n)=a \}.$$ My idea is to show that $\underline{C}$ is a substructure of $B$ and $G\subseteq C$. Then I can directly obtain $\underline{A}\subseteq\underline{C}$.
To show that $G\subseteq C$, let $g\in G$ and for a variable $x_1$, let $t=x_1$, then $t^{\underline{B}}(g)=g$ and hence $g\in C$.
Is this correct? Moreover, how do I show that $\underline{C}$ is a substructure?
Your attempt is fine. $\def\B{\underline B} \def\C{\underline C}$
For any $n$-ary basic operation symbol $f$ and elements $a_i={t_i}^{\B}(\vec{b_i}) \ \in C$ with all $b_{i,j}\in G$, just consider the composed term $\tau:=f\big(t_1(\vec{x_1}),\,\dots,\,t_n(\vec{x_n})\big)$, so that $$f^\B(a_1,\dots,a_n)\ =\ f^\B\Big({t_1}^\B(\vec{b_1}),\,\dots,\,{t_n}^\B(\vec{b_n})\Big)\ =\ \tau^\B(\vec{b_1},\dots,\vec{b_n})\ \in C$$ so $C$ is closed under the interpretation $f^\B$ of $f$ within $\B$.
This is necessary for enabling us to define the interpretation $f^\C$ so that it is the restriction of $f^\B$, because operation symbols must be interpreted as functions defined on every $n$-tuples.
On the other hand, for an $n$-ary relation symbol $R$, we can (and actually must) simply define $R^\C(a_1,\dots,a_n)$ to have the same truth value as $R^\B(a_1,\dots,a_n)$ for any elements $a_1,\dots,a_n\in C$.
This way the structure $\C$ defined on set $C$ (with the help of structure $\B$) is indeed a substructure.
Note that if the signature doesn't contain operation symbols, then every subset of any structure is a substructure (of course if we interpret each relation symbols as the restriction of those in the original structure).