All Questions
10 questions
0
votes
2
answers
223
views
Triggering EOF From Keyboard Input (Terminal)
I'm a new[er] programmer and going through K&R's "ANSI C" 2nd edition book. The example has the following program that counts characters using getchar() until EOF is reached.
include &...
0
votes
2
answers
178
views
Why single digit numbers are appended with "D" (in C output)?
Why single digit numbers are appended with "D" (in C output)?
The following code
#include <stdio.h>
int main(void)
{
int c = 0;
printf("%d\n", c);
return 0;
}
...
1
vote
1
answer
90
views
getchar() with EOF not behaving as expected
Working my way through K&R I stumbled uppon this unexpected behaviour. Consider following code:
#include <stdio.h>
#define MAXWLEN 10 /* maximum word length */
#define ...
-1
votes
1
answer
448
views
Character Counting Example From K&R [closed]
K&R
charcter counting Example
I am not able to get output as expected in the book.For Example, when I enter a input "I am Back" and press enter it should give back me an answer but its not Why ...
0
votes
2
answers
955
views
Program isn't accepting EOF to stop reading stdin
New to programming, working through K&R. After inputting using the stdin, I press ^D to write EOF (i'm using linux), and... nothing happens. I'm still able to write to the console, and able to ^Z ...
0
votes
1
answer
48
views
C:folding a line after a fixed column
I am trying to write my solution for the KnR problem 1-22. Below is my code which I am not able to get why it's not working. It just prints the whole line that I typed, without folding.
#include <...
3
votes
1
answer
3k
views
EOF exercise 1-6 K&R The C programming language
This is taken directly from the K&R book:
The precedence of != is higher than that of =, which means that in the absence of parentheses the relational test != would be done before the assignment ...
1
vote
2
answers
930
views
Very basic example code of "The C Programming Language" doesn't work like expected?
I'm a middle experienced Java developer and have many problems learning the C language for my computer science study. I try it with the book "The C Programming Language" which many people seem to ...
62
votes
5
answers
60k
views
How to simulate an EOF?
I am currently reading K&R's book and typing in the examples from the first section, and there are a couple of examples such as this:
while((c = getchar()) != EOF) {
//do something
}
I am ...
1
vote
4
answers
1k
views
how does this code from "The C Programming Language" work?
I'm reading "The C Programming Language (2nd ed.) and near the beginning, it has examples like this:
while((c = getchar()) != EOF)
if(c == '\n'){
++n1;
I can see how this would work while ...