working C code (in class)