cards.c: Loop and Invalid Check Added