947 questions
-1
votes
3
answers
176
views
Is there a reason why I don't see much of getchar() used in c? [closed]
When I see code for getting input I see scanf() used most of the time. I see some from the link taking-string-input-space-c-3-different-methods and I also see it on this website.
Is there something ...
0
votes
0
answers
53
views
Simplest timer in C [duplicate]
I am trying to make the simplest timer program in C. My attempt is as follows:
#include <stdio.h>
#include <time.h>
int main()
{
char c;
time_t start, end;
long int day, ...
1
vote
2
answers
120
views
getchar() keeps waiting after input - continues only after pressing ENTER again
I am having a problem with my program getting stuck on waiting for input after using getchar(). I used a loop to clear the buffer and the same functionality appears four times in my program but only ...
2
votes
1
answer
83
views
k&r: Exercise 1-18. Program takes input but doesnt produce any output?
i'm currently going through K&R. right now i'm at exercise 1-18: "Write a program to remove trailing blanks and tabs from each line of input,
and to delete entirely blank lines.".
...
3
votes
3
answers
118
views
Issue with getchar() Skipping Input in a C Program
A number guessing C program; After the 4th iteration which prompts “well, is it 5 then?”, the character \n (enter) still remains in the buffer which then gets read by the first getchar() in the while ...
3
votes
5
answers
141
views
getting a stream of -1 when I pass EOF in an infinite getchar printf loop
I have just started the K&R book. It introduces a loop using getchar() and putchar() to copy characters from input to output until EOF is reached:
main()
{
int c;
while ((c = getchar()) !=...
3
votes
2
answers
141
views
Linux: Catching Ctrl+C breaks stdin
I'm writing a test application for a console text input library. The idea of that part of the library is to just treat any input as a regular text input, even Ctrl+[letter] combinations. And for the ...
0
votes
0
answers
32
views
Why can't I get an output on the printf statement in C language right after the scan statement, the run command skips it completely [duplicate]
I am new to C language coding, I was trying to learn the various inputs that I can take from the user and display the same but I keep getting a blank in the place of the printf statement that takes ...
2
votes
1
answer
101
views
How to detect the Enter key when pasting multi-line text (containing `\r`)?
While developing a line editor in C++, I'm using getch() to capture each key input, and see \r(13 in ASCII) as the Enter key. However, when pasting text that contains multiple lines, the program ...
0
votes
1
answer
92
views
Ungetc() Not Ungetting Character
My code is extremely simple, but I figure that's best to figure out what's going on in my program. For some reason, I can't seem to get ungetc() to work properly, nor can I figure out it's purpose. ...
-1
votes
2
answers
96
views
How can i make a C program exit when key Q is pressed?
i am making a counting program, and i want to add a feature that quits the program, but i don't really know how to do it. i have seen examples on how to do it, but all of them are for windows. please ...
0
votes
0
answers
61
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
82
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
86
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
97
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 ...