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

getChar() to remove a word from a paragraph in C

Lets say i have a paragraph, and in that paragraph i want to remove the word bus. I use getchar() to get the input. How do i go about doing this. int main() { while ((character = getchar()) != EOF) { if (character != '\n') {
Rashad
  • 3
  • 4
-4
votes
1 answer

Why is putchar() printing out the char with the "%" symbol?

I have the code: #include int main(void) { int c; c = getchar(); putchar(c); return 0; } and after compiling and running, when I input k for example, it prints out k%. Why is it printing out %? Edit: I tested a few things…
hwkd
  • 2,411
  • 3
  • 18
  • 27
-4
votes
2 answers

What does this program do? (Self calling main function + getchar)

Can anybody help me explain this question from a past exam paper? When I compile it, it is never satisfied with any input. Also, what is the reason for the self calling main function? What does the following program do? Justify your answer. #include…
Snoviet
  • 3
  • 1
-4
votes
2 answers

Writing a word count program in C

In this program a word is defined by any sequence of characters that does not include a "-", " ", "\n", ":" or "\t". So "howdy-hi:slig" would be three words in this program. while ((iochar = getchar()) != EOF) { if (iochar == '\n') { …
collinskewl2
  • 75
  • 1
  • 3
-4
votes
2 answers

getchar() function

I am currently trying to count the digits of a number using getchar(). If i do it with getchar (condition to not count the point or comma) and I put a number like 345.234 does it count 6 like 3-4-5-2-3-4 or does it count 4 like…
Lind
  • 277
  • 2
  • 5
  • 16
-5
votes
2 answers

C reading input in while loop

In c what does this do after gets int c; while ((c = getchar()) != EOF && c != '\n'); I saw that many of you are telling me its while loop and all, why so much complication to it? Why cant we just use this code which I have given…
Savn
  • 23
  • 5
-5
votes
2 answers

C converting char to int

I'm trying to build a program in C that: Gets age of user Checks if age is between 18 to 120 Checks if age doesn't contain other characters such as letters, dots and so. If it isn't between 18-120 or contains other characters go back to section…
Adam Morad
  • 167
  • 1
  • 7
-5
votes
2 answers

Possible output of the following program fragment?

for(i=getchar();; i=getchar()) if(i=='x') break; else putchar(i); Answer is : mi Can someone explain this piece of code ?(MCQ Question)
Abdul
  • 69
  • 3
-6
votes
1 answer

why the program is not terminating in gcc?

Why the program listed below is not terminating. I am using gcc compiler in linux. #include int main(void) { int c; printf("Enter characters: "); while((c = getchar()) != EOF) putchar(c); return 0; }
-7
votes
1 answer

c programing what is the meaning of this getchar and EOF and what this code do i didn't understand

count = 0; while ( (c = getchar()) != EOF) { if (c != '\t' && c != '\n') continue; if (c == '\n') break; if (c == '\t') count++; } what is the code mean and the getchar and EOF mean I did not understand
-8
votes
1 answer

C Program to count number of alphabets in a word giving error

Following is the code: #include int main() { int alpha = 0, input; while((input = getchar() != EOF)) { if(isalpha(input)) alpha++; } printf("Num of alpha is %d", alpha); return(0); } I'm…
1 2 3
61
62