Gas in your stomach is primarily caused by swallowing air when you eat or drink.
Most stomach gas is released when you burp.
Gas forms in your large intestine (colon) when bacteria ferment carbohydrates — fiber, some starches and some sugars — that aren’t digested in your small intestine.
If you have stomach problems then it is better to avoid drinking coffee.
Anyway, I wrote an infographic (can coffee cause gas?)about what to do before drinking coffee to avoid flatulence.
If you like it please feel free to share and comment on it.