Linked Questions
41 questions linked to/from I am not able to flush stdin. How can I flush stdin in C?
0 votes
1 answer
4k views
How to clear the keyboard buffer in a C console application? [duplicate]
Code is as follows: #include <stdio.h> #include <signal.h> #include <stdlib.h> #define SIZE 1024 char buffer[SIZE] = {0}; void timeout(int sig); int main(void) { signal(...
0 votes
1 answer
726 views
Code making an infinite loop when ask input with scanf [duplicate]
i have a function that ask to the user to enter a value to calculate its square root, however when i try to validate that the number of the input must be a number and not a char, it makes an infinite ...
123 votes
20 answers
543k views
How can I clear an input buffer in C?
I have the following program: int main(int argc, char *argv[]) { char ch1, ch2; printf("Input the first character:"); // Line 1 scanf("%c", &ch1); printf("...
5 votes
8 answers
8k views
How can one flush input stream in C?
I am not able to flush stdin here, is there a way to flush it? If not then how to make getchar() to take a character as input from user, instead of a "\n" left by scanf() in the input buffer?? #...
6 votes
4 answers
16k views
fgets instructions gets skipped.Why? [duplicate]
Whenever I do a scanf before a fgets the fgets instruction gets skipped. I have come accross this issue in C++ and I remember I had to had some instrcution that would clear the stdin buffer or ...
2 votes
3 answers
8k views
Dev-C++ Input skipped
#include<stdio.h> #include<conio.h> main() { int i; char c, text[30]; float f; printf("\nEnter Integer : "); scanf("%d",&i); printf("\nEnter ...
2 votes
5 answers
4k views
scanf in while loop
In this code, scanf works only once. What am I doing wrong? #include <stdio.h> #include <unistd.h> int main() { int i = 1; if (! fork()) { while(i) { ...
-3 votes
2 answers
9k views
Dev-C++: 'prinft' undeclared
I´m completely new to programming and just started some tutorials from the internet. One of them suggested this code for an easy question for the user: #include <stdio.h> #include <stdlib.h&...
0 votes
3 answers
3k views
fork() system call and while loop ( part 2)
Does anyone know why the printf("Type q to quit") line prints twice in the terminal when I run this code: #include <stdio.h> #include <unistd.h> int main (int argc, char *argv[])...
2 votes
3 answers
2k views
I don't understand why I can't get three inputs in c
A friend of mine is trying to learn c (on her own, with a book) and sometimes she asks for help. She just showed me something I can't answer; I'm ashamed but I studied C in college and then moved to ...
2 votes
1 answer
1k views
String problems in C: operands of unequal types, char[255] and char*
When i try to compile my code i get the following errors: error #2168: Operands of '=' have incompatible types 'char [255]' and 'char *'. error #2088: Lvalue required. i get these errors for the same ...
0 votes
3 answers
2k views
Skips over my fgets
I am programming in C. For some reason is just skips over my fgets and runs the code afterwards and I don't know why. char content[256]; printf("What do you want it to say?\n"); fgets(content, 256, ...
2 votes
4 answers
2k views
While input is not a number, goes into Infinite loop
I'm just a beginner and am trying to make a a program that asks for a number and if a letter is input, it says "that's not a number" and asks for a number again, until a number is input. However, my ...
1 vote
4 answers
1k views
scanf reads previous line instead of getting new one
I have the following code: #include <stdio.h> int opt; scanf("%d",&opt); while(opt!=0) { switch(opt) { case 1:func1(); break; case 2:func2(); break; case ...