I had that problem before.. Mine was the battery, I changed to a new one and the problem was gone. I had to test everything before though cuz it could've been the alternator too.
Easy test you can perform to see if its the alternator or the battery that's causing the trouble: Losen the positive terminal (+) on the battery and take it off
while the car is still running. If the car still runs after you take off the terminal then its the battery that's at fault, because this means the alternator still provides a good current(12V) to the car to keep running. If the car shuts off, then your alternator is gone.