The observer has a line of sight to the star, but the cloud of gas is in the way. The cold gas (which is not glowing like the star is) will absorb only certain frequencies of light, depending on the atoms which make up the cloud. The absorption spectrum (C) shows the continuum of the star, with the missing wavelengths absorbed by the cloud. By analyzing which frequencies get absorbed, you can identify the composition of the cloud.