It seems you're making the common mistake of not watching for line endings when reading user input.
If the user puts in 1
what's really in the input buffer is 1\n
(they had to push enter, right?) and you call getchar
to get the 1
so the buffer now contains \n
. Then when you call getline
to get the path, it's going to read until the first new line. So it gets an empty string.
After your getchar
you should call ignore
to skip over the newline.