Implementation in c