when using system() is there a way I can capture the result of it? (ex: the actual error/output on the screen)

Or is there a better way to execute shell commands? In most cases if I can I use built in functions to accomplish the task that I'm using system() for, but in some cases I have to use system(). My program is to administer a Linux server so it does stuff like create/edit/delete users, etc.

One way I'm thinking is I can pipe it to a temp file then read the file, but that's kinda messy, I'm wondering if there's a better way.