Must used C standard functions rewrite for educational proposes