First we duplicate the stdin file descriptor so when SDL calls close() on 0 the stream remains open.
int dup_fd = dup(0);Then we initalise SDL, and let it redirect stdin as it does.
SDL_Init(SDL_INIT_VIDEO);Here is where we do our little trick: close 0, then duplicating the original stdin stream back onto 0, so scanf etc will continue to work.
close(0);And viola! We have stdin back again, no longer redirected. This solution won't work for window users though. See discussion at gmane.org.