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
-3
votes
1 answer

What is wrong with this C function? (printf() with getchar())

printf( "%3o\t%2x\t%3d\t%c\n", c = getchar(), c, c, c ); I'm getting a warning that says "unsequenced modification and access to 'c' [-Wunsequenced]". The error is fairly easy to fix; all I have to do is separate getchar() from printf(), but I…
user628544
  • 227
  • 3
  • 9
-3
votes
1 answer

using getchar() in C

When using getchar() in C, you get a ascii value for the character entered. If you needed to loop through values entered using getchar() and convert the number entered ('.' included) to floating point how would convert the value and also read in…
MD_90
  • 5
  • 1
  • 6
-3
votes
2 answers

for-loop and getchar() in C

Why does the code get the empty data directly in even times? I have no idea what is going on. Thank you very much. #include #pragma warning(disable : 4996) void main() { int f, a = 10, b = 20; for…
-3
votes
1 answer

Getting weird characters using getc?

So I'm starting to implement a Huffman tree, and to do that, I'm trying to get character values from stdin or a input file. The input file (just a string "cheese") is being added to the array freqcounts, where the index of freqcounts that is being…
-3
votes
3 answers

Where to use this while loop?

I've just started to learn c programming. I don't know weather this question is silly or not. Where do i use while(getchar()! ='\n') ; When using scanf function in some program the above mentioned while loop is used whereas some other program…
overmass123
  • 21
  • 1
  • 4
-3
votes
4 answers

How can I get the next char even if it is whitespace?

Is there a function like getline or getchar that will get the next character even if that char is whitespace? So if I had a bc, I would have to call that function four times to get the 'a', ' ', 'b', and 'c'.
Matt
  • 1
  • 1
  • 5
-3
votes
1 answer

getchar and EOF C programming

#include int main() { int c; while ((c = getchar()) != EOF) { putchar(c); } } This works fine, when EOF ( ctrl + z) is in a new line, but when the input is :blabla^z it does not work. When i debug the program it tells me that…
sebastian
  • 13
  • 5
-3
votes
1 answer

Get just one char from long keypress python curses [accepted]

Hi I'm writing a program in python curses and I need to get just one char from a long keypress. (In other words what I need is that if i keep pressing down a key my program just has to get the char with the function getchar() just once). I need that…
Alessio Ragno
  • 476
  • 1
  • 6
  • 20
-3
votes
1 answer

difficulties using getchar for arrays C

This is my code.i want to extend this code to ask user to enter name,address,phone and town and print it out.i did the main parts declerations etc but while using getchar i have some difficulties.what to do? #include #include…
hlap
  • 11
  • 1
-3
votes
1 answer

Counter is not incrementing properly

my counter does not seem to increment (for c programming) int ch; int counterX = 0; int counterY = 0; while(( ch = getchar()) != EOF ) { if (ch == 'X'){ counterX = counterX + 1; } if (ch == 'Y'){ counterY = counterY…
user2947725
  • 41
  • 3
  • 9
-3
votes
1 answer

getchar() returns immediately

I'm programming C in Visual Studio 2013 Express for Desktop, and when I use getchar() it terminates immediately. Here's the code: #define _CRT_SECURE_NO_WARNINGS #include int main() { int num1, num2; printf("Enter first number:…
Travier
  • 205
  • 2
  • 9
-3
votes
4 answers

C program, scanf for a char, then reprinting it?

#include int main(void) { char fever, cough; printf("Are you running a fever? (y/n)\n"); scanf("%c",&fever); printf("Do you have a runny nose/cough? (y/n)\n"); scanf(" %c",&cough); printf("Please verify the…
J T
  • 23
  • 1
  • 1
  • 1
-4
votes
1 answer

getchar() for excluding chars from input

Here is what i'm trying to do: My teacher gave me an assignment to recieve input from a user like "1,2,3,4,-3,17,-9,0,5,-8,10" and after the user has pressed enter key the program should ignore the "," signs and print the maximum and minimum values…
-4
votes
1 answer

What is "Segmentation Fault (core dumped)" and why is it being returned in my output?

I am trying to replace the loop containing repeated getchar calls with a single call to fgets When I try to type an input I get Segmentation Fault (core dumped) and I don't know what that is or why I get it. Starter Code /* Example: analysis of text…
-4
votes
1 answer

not able to understand the role of getchar and putchar here

#include #include int main() { int c; c = getchar(); while (c != EOF) { putchar(c); } return 0; } when I compile and give input ABC and then press enter, the never ending loop starts like…
secret
  • 1
  • 1
1 2 3
61
62