p is a pointer to a single char. If you enter "hot.txt\n" for line 4, you will exceed the bounds of the memory you allocated, causing undefined behavior and bad things will happen. You have the same issue with x.