Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • Thanks for response. 1. You open stream in append mode and read from it. I suppose this triggers undefined behavior because you can't read from such streams. Moreover in file opened read-write you can't jump between reading/writing without some fflush, fseek or whatever in-between them. 2. In my, possibly wrong, interpretation APUE and GCC docs talk about different streams and how reading from one of them, triggers the flush on the other. The 1st example with stdin/stdout show that, it would be more educational to see it on a different pair of streams as this concrete case feels natural. Commented Nov 9, 2024 at 12:36
  • 1. thx, I fixed my post 2. I can reproduce your original problem, I also don't get "Hello". The conclusion is that an explanation in Advanced Programming in Unix Environment doesn't apply to glibc. Some even say this practice is harmful stackoverflow.com/questions/39536212/…. I don't know if glibc implementation is explained in detail, reading the source code is a huge pain. Commented Nov 9, 2024 at 17:33