Linked Questions
12 questions linked to/from How to clear stdin before getting new input?
4 votes
2 answers
2k views
How to flush stdin without requiring user input? [duplicate]
I'm trying to simulate a command line shell. The user inputs a shell command they want to input, e.g. /bin/pwd and the code is meant to execute it. The buffer is set to read a fixed number of chars (...
0 votes
0 answers
80 views
Using fgets() and gets() string function to see their difference. However, buffer problem is encountered while working with string [duplicate]
fgets() and gets() works properly for the first time. When I use this function for the second time then I am not asked for the input. #include<stdio.h> int main(){ char name[10]; printf(&...
0 votes
0 answers
40 views
How to discard a string input once it's invalid in C [duplicate]
I'm reading the terminal input of characters with the getchar() function and from it I have to store the duration and the description of a task. What I'm trying to figure is how to discard the entire ...
13 votes
5 answers
53k views
Checking the 'stdin' buffer if it's empty
I am trying to read a number character by character, but I don't know if the stdin buffer is empty or not. My first solution was to look for '\n' character in the stdin buffer, but this isn't any good ...
1 vote
4 answers
711 views
Using fgets() function in c
I am a newbie in C. Consider my following code: #include <stdio.h> #include <string.h> int main() { char strs[5][6]; char temporary[5]=""; for(int i=0;i<5;i++) ...
2 votes
1 answer
2k views
Explanation about detecting end of line in C
I'm reading/practicing with this book about C language: "C Programming - A Modern Approach 2" and I stumbled upon this piece of code whose explanation is odd to me: Since scanf doesn't normally skip ...
2 votes
1 answer
704 views
How to prevent fgets running multiple times when overflowing a buffer?
I have a problem where if a user enters an input greater than the max number of characters such as "abcdefg" when the max is 5, the fgets() that is within a loop runs twice and instead of "abcd" it ...
0 votes
2 answers
1k views
WinError 10038 Alternatives to sys.stdin on Windows?
I was reading up on Python Networking using sockets and found the code below at the end. I have the server file which works fine and starts the server on port 9009. # chat_client.py import sys, ...
0 votes
1 answer
750 views
C program prints to terminal instead of file even after using dup2/dup
I'm in an operating systems course and doing assignments with C on Linux. In one of the assignments I was supposed to redirect and output to a file, but for some reason, I keep getting the output in ...
2 votes
2 answers
204 views
Make the program stop after user enters a value
I am building a quiz project on C. My question is, can I use a command or use something to make the user decide if he wants to keep answering questions or not. For example here is a part of my code. ...
1 vote
3 answers
366 views
My main while loop will run, and run again when the user enters 'y' or 'n'. Regardless of what the user says
When I added the main while loop, the program just always runs, and runs through again and with a message telling me there is invalid data (from my first input validation). Can anyone show me how to ...
2 votes
2 answers
261 views
ch2=getchar() doesn't work after last input loop while((ch=getchar())!=EOF)
#include <stdio.h> int main(){ char ch; while((ch=getchar())!=EOF){ putchar(ch); } char ch2 = 'A'; printf("ch2=======>%c\n",ch2); ch2 = getchar(); printf("...