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`.

Anything related to C or C++ standard library functions getchar (defined in <stdio.h> C standard header) or std::getchar (defined in <cstdio> C++ standard header). These functions are used to read a single character from the standard input stream stdin.

See CPPreference.com:

926 questions
-2
votes
2 answers

How does getchar_unlocked() actually work?

What is the inner working of getchar_unlocked()? Why is it thread unsafe? And why it is not employed in windows POSIX?
-2
votes
3 answers

What if we do not store the input character?

#include int main(void) { getchar(); return 0; } In the above sample code, if the user enters a character, then what will happen to it. Will it be placed at some memory location or not?
zee
  • 188
  • 2
  • 2
  • 9
-2
votes
2 answers

getchar() working abnormally

I am trying to read characters one at a time and convert them to int in a cumulative manner. If the user enters a character other than a number i start the whole process all over again. When i run this code, the code below getchar() gets executed…
thunderbird
  • 2,715
  • 5
  • 27
  • 51
-2
votes
1 answer

how to add new line character between #include and int main() { }

i'm writing a program that takes input as sequence of characters using getchar() and create pro.cpp source code file using fopen() and putc() functions. when i compile this source code files created by this program it generate error. this error can…
siddstuff
  • 1,215
  • 4
  • 16
  • 37
-2
votes
2 answers

Whats wrong with char input for this 2 dimensional char array? why its not taking total of K*K inputs?

I am trying to take 2 dimensional char data from user, but it's not taking input from user properly. Could you highlight the bug in following code? #include #include #include int main() { int i, j, k; char…
chandan
  • 11
  • 1
-3
votes
1 answer

Im a beginner to C and getting an error with my code: assignment to char from char * makes integer from pointer without a cast. How could I fix this?

Im trying to write a code that gets vowels from a string and replaces them with a "*" before outputting the changed string using the functions of getchar() and putchar(). char input_char; input_char = getchar(); while(input_char != EOF) { if…
user19746829
-3
votes
1 answer

How to wait and READ char from stdin without waiting?

Hello There is a file where I draw picture using a loop. I want to exit loop when 'q' button is pressed. But I want the program is running during it is waiting 'q'. How to implement this behavior? I tried using system("stty -icanon min 1") but in…
-3
votes
1 answer

getchar() skip the first character when tried to scan the input

I'm trying to scan the input from terminal and I'm trying to scan the initial white space but the program just skip it. I tried using this method before in a different program but it doesn't work in my new one. Plz help!!! #include…
hry0918
  • 35
  • 4
-3
votes
1 answer

How to use getchar() with string?

I try to get a text attached to the array but this does not seem to work when I try to use printf after. It does print a blank space. char text[10][30]; // 10 is text count and 30 text length printf("Enter text: "); text[0]=getchar();
Stefi Zuzu
  • 35
  • 7
-3
votes
1 answer

Why is type int needed to handle EOF and return of getchar()?

As written in book- The problem is distinguishing the end of the input from valid data. The solution is that getchar returns a distinctive value when there is no more input, a value that cannot be confused with any real character. This value is…
Abhishek Kumar
  • 125
  • 3
  • 10
-3
votes
4 answers

Please explain this code involving getchar and putter

I attached a picture of a piece of c code that I don't completely understand. I know that getchar returns the next character from standard output and that putchar puts the character on the standard output, but i don't fully understand what the EOF…
-3
votes
1 answer

Cannot get my getchar() function to work how I want it to work, output is10 not 2 c++

I cannot figure out why my getchar() function is not working the way I want it to work. I am getting 10 not 2. Please take a look. Main(): #include #include #include using namespace std; int main() { int var,…
Dustin177820
  • 111
  • 6
-3
votes
1 answer

problems when using getchar() repeatedly in C

My code: #include "stdio.h" main() { char a,b; a=getchar(); b=getchar(); putchar(a); putchar('\n'); putchar(b); } getchar() requires user to enter a character and then press enter to assign it to the variable. I expected…
AtlasRE
  • 1
  • 1
-3
votes
1 answer

getchar() stopping after printing one value

Function of the code: The function of my code is pretty simple. It converts a phone number with numbers into a phone number. #include main(){ char num; printf("Please enter a phone number with letters to be converted into a phone…
Manny
  • 27
  • 8
-3
votes
1 answer

string run time error working only with getchar why?

i am using visual studio 2013 for desktop and i have run time fail with the string i don't know why this isn't working. int main(void) { char string[MAX1] = "THANK "; char you[MAX2] = "u"; strncat(string, you,…
yarden
  • 23
  • 4