Also, I saw it just now, you're using the gets() function to collect a string from a stream (stdin). gets() is a old and evil function (bugged too...) you should use instead the fgets() function.