How do I implement this in C?