the definition of a mole is the atomic weight of a compound in grams
in this case, Mg = 24.3, C = 12.0, N = 14.0
for the compound Mg(CN)2, the atomic weight will be 24 + (12*2) + (14*2) = 76.3g/mole
the amount of Carbon = 24/76.3 = 0.31 or 31%
you have 3.4moles of Mg(CN)2
76.3g/mole * 3.4moles = 259.4g
the total amount of Carbon = 259.4g * 0.31 = 80.4g
80.4g/12g/mole = 6.7moles of Carbon