A different approach would be using fgets(), which is more safe than gets().