I wrote a C program. (Question at bottom of page) I can provide actual code, but I don’t think it is necessary for this question to be answered.
Used a while loop with fgets to get sizeof line
Assigned that fgets to line[255] in the fgets
Assigned the line to a char* (inside the loop)
Printf the char* (also inside the loop)
C program outputs as expected.
I used strace -o x.txt ./a.out to see what is going on behind the scenes.
I see this: (of course there is a lot more garble above/below it I don’t understand)
read(3, "text\nMore text\nEven more text"..., 4096) = 72
write(1, "text\n",5) = 5
... more of the write() = #
read(3, "", 4096) = 0
close(3)
Question:
-
I get the
write(1=stdout, "text to print", #of char)or is this # of byte? -
I do not understand the
read(3, "", 4096) = 0
I know 0=stdin, 1=stdout, 2=stderr, do not know what 3 means – maybe this is the file?
I do not know why it is doing another read, and I assume 4096 is what the buffer size?
My best guess is that since it is saying = 0 because its EOF ?
Number of chars
The file you have opened. 4096 is buffer size. Last read has failed to read any bytes (0 bytes).