Reputation: 1233
void deleteFile( FAT *allotable ) {
/* PRECONDITION: This function expects a FAT structure that is valid.
* POSTCONDITION: A file is flagged as removed from the disk and it will
* be possible to write over it
*/
// Local variables
unsigned char test[9] = { 0 };
// Select file to remove
// TODO: The user will select the file to remove based on the
// listing in listDir
// For testing, we are removing file at location 0 in the entry
fgets( test, NAME_SIZE, stdin );
return;
}
When I run the function and type in a string, I see the string printed back in stdout. I am sure I have an issue with a buffer, but I can't seem to figure this out.
Upvotes: 1
Views: 980
Reputation: 63471
When you type characters into the console, they are echoed back to you. The characters will still be read when you read from stdin
.
Alternatively you can pipe the output of a program into your own, or redirect a file to stdin. In those two cases, the characters will not be echoed:
echo Program output | ./myprog
or:
./myprog < fileinput.txt
edit - Sounds like it's a terminal problem.
You haven't stated what system you are using or how you are interfacing with it, but I can get this behaviour by connecting to a system via SSH with PuTTY.
I change the terminal settings to force on both "Local echo" and "Local line editing". Then I get the line echoed whenever I press enter. Obviously only one of those should be on. Preferably "Local echo".
Upvotes: 0
Reputation: 780974
A common cause of this is having echoing enabled in both your terminal (presumably an emulator these days) and in the OS terminal driver. Assuming you're using Unix, does the problem go away if you do:
stty -echo
before running your program?
Upvotes: 0
Reputation: 9336
When you run it if you see:
./program
input<CR>
input
<prompt>
Then the code you provided was not responsible for doing that. Use some debug statements or a debugger to figure out where that echo is coming from, because that isn't what fgets does.
If you are seeing:
./program
input<CR>
<prompt>
Then that is just how terminals work. They will echo back the text as you type unless you disable that feature (useful for entering passwords).
Upvotes: 1