How to write custom events in c