modify ex1.c: add check valid character instance