Questions tagged [getchar]
Anything related to C or C++ standard library functions `getchar` (C) or `std::getchar` (C++). These functions are used to read a single character from the standard input stream `stdin`.
getchar
939
questions
0
votes
0
answers
60
views
Why does my printf function not work? Is my while loop not ending? [duplicate]
I am just trying to copy and paste the text input. After which the code must show done.
#include <stdio.h>
/*code to copy all input characters and paste it one by one*/
int main()
{
int c;
...
-1
votes
1
answer
65
views
getchar() taking stuff which I print using printf()
#include <stdio.h>
int main() {
int c;
for (int i = 0; i < 10; i++) {
c = (getchar() != EOF);
printf("%d\n", c);
}
printf("As we can see, the value of c is ...
3
votes
1
answer
73
views
Strange printf not working after a getchar and getchar skipping
I'm getting crazy with C.
I'm programming with JavaScript, Ruby, Python, PHP, Lua, even Java...
Recently, I tried to program a simple Read-Eval-Print-Loop in C.
And I have a very strange behavior with ...
0
votes
2
answers
84
views
getchar() and its buffer
I wrote this code to get familiar with getchar(). I took line
while(ch != '\n' && ch != EOF)
ch = getchar();
from a book. What is a mystery to me is that in the second while loop using ...
0
votes
3
answers
77
views
getchar() and space-character
I am experimenting with the getchar() function. Can someone please explain why every time I finish an input line with a space and then press Enter, the input window skips a line and then I have to ...
1
vote
2
answers
66
views
Why does this python program hang the terminal when it exits on Linux or WSL?
From what I can tell, this program confuses the terminal emulation on both Linux and WSL, on both python 2 and 3.
Once the program exits, characters are no longer echoed and normal terminal function ...
1
vote
1
answer
82
views
Does getchar read ctrl+z or return EOF?
I have this code:
#include <stdio.h>
int main(void) {
int d=0;
d = getchar();
printf("%d\n", d);
}
Output:
^Z
-1
From what I understand there are two things that could be ...
1
vote
0
answers
37
views
getchar is able to read ctrl+z but not scanf?
What I want to do is find out if scanf can read ctrl+z as EOF? I know that getchar and scanf return EOF when the end of the file is reached. This I have no problem with. What I want to do is have them ...
0
votes
2
answers
81
views
Why does getchar in C accept many characters in a loop but not outside one
In the following program:
#include <stdio.h>
int main() {
int c;
c = getchar();
putchar(c);
}
Even if If write many characters in the input and press enter, it only prints the ...
3
votes
5
answers
150
views
Does a character have to be casted to unsigned char before being compared to getc family returns?
I am not sure about whether I have to cast a character to an unsigned char before being compared to the return of a getc family function.
The functions I consider getc family, are getc, fgetc and ...
1
vote
0
answers
41
views
why getchar() doesn't read the input? [duplicate]
#include<stdio.h>
int main(void){
int character;
double balance,amount;
printf("Enter the balance: ");
scanf("%lf",&balance);
printf("Enter ...
-1
votes
1
answer
92
views
what is the use of getchar() in following program [duplicate]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define NUM_DAYS_IN_WEEK 7
typedef struct
{
char *acDayName;
int iDate;
...
1
vote
1
answer
52
views
Why am I doing wrong with getchar()? (initializer element is not constant)
The code:
#include <stdio.h>
#include <stdbool.h>
typedef enum{
counting1,
counting2,
searching,
possiblecom,
possibleend,
} read_state;
bool issep(char a){
return (a == ' ' |...
0
votes
1
answer
105
views
Why does while((c = getchar()) != EOF) repeat 2 times in c programming?
When I enter a number from keyboard, while loop goes 2 times, and I didn't understand why it is doing that. I want to run this loop for one time after each entering number. Is there anyone who can ...
0
votes
2
answers
68
views
getchar() prompting for input when typing space before Enter
A part of the code I'm writing has to read a sequence of integers separated by a space from input into an array.
It works fine when I input, for example, 3 numbers, and then press Enter. But if after ...