Event driven coding in c