3 ms·
There is a bug in this example: char ch; while ((ch = fgetc(in)) != EOF) { fputc(ch, out); } https://little-book-of.github.io/c/books/en-U
by omoikane 1y ago
There is a bug in this example:
char ch;
while ((ch = fgetc(in)) != EOF) {
fputc(ch, out);
}
https://little-book-of.github.io/c/books/en-US/book.html#example-copy-text-from-one-file-to-another https://little-book-of.github.io/c/books/en-US/book.html#exa...
The return type of fgetc() is `int` and not `char`. This example will not differentiate between end-of-file in input versus reading 0xff. 82.7 appears to be the only example with this issue, all other places with fgetc correctly uses `int`.
----
I found another section with lots of syntax errors, for example:
int x = 10;
int *p = &x;
int pp = &p; // Should be int **pp
https://little-book-of.github.io/c/books/en-US/book.html#adding-another-layer https://little-book-of.github.io/c/books/en-US/book.html#add...
Most likely because the two asterisks needed for pointer-to-pointer isn't rendering properly.
- _zagj 1y ago> The return type of fgetc() is `int` and not `char`. This example will not differentiate between end-of-file in input versus reading 0xff Be aware that character literals in c, e.g., 'f' or 'A', have type int for probably this reason. From the ANSI C89 spec: > An integer character constant has type int. The value of an integer character constant containing a single character that maps into a member of the basic execution character set is the numerical value of the representation of the mapped character interpreted as an integer. However, in C++, they have type char.
- tamnd 1y agoI have fixed some bugs here: https://github.com/little-book-of/c/pull/4 https://github.com/little-book-of/c/pull/4 Let me carefully review all the code snippets, create tests, and integrate them into the CI/CD pipeline to make sure everything is correct.
- tamnd 1y agoMy next step is to extract all the code into the "src/" folder and set up proper CI/CD to test everything. Could you help create some GitHub issues? I will fix them in my free time next weekend.