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

storing each word in a 2d string C

i want to store each word in a 2d string. The code i wrote is working with no errors the only issue is when there are two spaces or more, it stores the space as a word. If anyone knows how can i fix this This is my code: #include #include…
Moe
  • 17
  • 7
-2
votes
3 answers

getchar() in switch()-function doesn't work

so I was trying to program my first project on my own and already have some troubles concerning the getchar()-function. What I want to do is to get user input without having to press enter. The user-input than should "activate" the case equivalent…
user14813784
-2
votes
1 answer

Exercise 1-8. Write a program to count blanks, tabs, and newlines

it's the K and R c programming exercise, I don't know why my program doesnt work, could anyone help, please and thank you. When I run the program and type a line of words or two and hit 'Enter', it doesnt show anything, it just jumps to the next…
Chihiro
  • 1
  • 2
-2
votes
1 answer

Printing numbers in C

So my problem is this I want to print numbers that come from the terminal while the numbers are different than the EOF. For example if put 007 as the input, I want the output to be 7 or if I put 42 I want the output to be 42. But for some reason,…
Martim Correia
  • 483
  • 5
  • 16
-2
votes
1 answer

Why the return type of getchar() is int?

I searched for the answer on Internet but I could not understand what is this 'EOF'? Please let me know from basic about what is getchar() and what are it's uses? Note that I am just a beginner of C language.
Khushi Puri
  • 1
  • 1
  • 3
-2
votes
2 answers

My Program do not take input from the scanf command

#include void aeins(){ int x; unsigned int y; double z; printf("Geben sie einen ganze Zahl ein: "); scanf("%d", &x); printf("Geben sie eine natürliche Zahl ein: "); scanf("%u", &y); printf("Geben sie eine…
-2
votes
1 answer

why printf("%d", getchar()) printing an extra 10

In the program, printf("%d", getchar()) is printing an extra 10. when i give input like a, it prints 9710 instead of 97, same for others #include int main() { int c; while((c=getchar()) != EOF) { printf("%d", c); } …
-2
votes
1 answer

write getc() return value to file as char

How do I write the return value from getchar() function to a file? I tried the following and it wrote integers to the file. Preferably in a C++ solution? myFile.open("somefile.txt", ios::app); myfile<
Lightsout
  • 3,454
  • 2
  • 36
  • 65
-2
votes
1 answer

Reading strings into 2 dimensional array in C

I want to read a number of strings from a text file (standard input) to a 2 dimensional array using getchar(). please ignore the magic number in the code. #include #include int main(int argc, char *argv[]) { char…
Andrew
  • 1
-2
votes
2 answers

C program crashes when using getchar after allocating memory

I'm making a C program where I have to use -ansi and -pedantic. I want to read the stdin input but when I call getchar() the program crashes. Here is the line that makes the error : while((data = getchar()) != EOF) { When I run it normally it…
-2
votes
2 answers

C - Why does this loop repeat, even when the right input is given to break it, using getchar()?

(New to C and programming in general.) When I run this small program to prompt a user to enter 1 or 2, I want to check if the input is correct, so I ran a while loop that was supposed to run until the correct input is given. But even when I type 1…
B.M. Corwen
  • 205
  • 3
  • 10
-2
votes
1 answer

Program won't store characters in 2d array in c

I am creating a program where I insert a number of sentences and the program outputs them in order. I have finished the program, but when I run it it seems like the characters I input into the array aren't displayed or stored correctly, getting as a…
PabloD
  • 3
  • 3
-2
votes
1 answer

How to read text file in C without fopen

can anyone help me? I need to read a file called address.txt and work with each word in there (I have one word per line to make it simple). I am forbidden to use these functions: Malloc, freee, fopen, fclose, fscanf,... qsort, lsearch, bsearch a…
-2
votes
3 answers

Using putchar() and getchar() to print individual characters

I'm trying to use putchar() and getchar() to read in a string of characters from the user, and then my loop will print each character three times, print a new line, etc etc, until every character in the variable "userInput" has been printed. When I…
A.Coder
  • 51
  • 3
  • 8
-2
votes
4 answers

How are getchar() and putchar() Macros?

From what I understand about macros in C, they are predefined constants that will be used throughout the program with their constant value, so we go ahead and define them to avoid further complications and make the code more readable, so people…
AliMan
  • 155
  • 7