Value of EOF in C | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

Value of EOF in C

Im trying to print the value of EOF (K&R) I get some symbols I dont understand before the value when printed. Could someone help explain why? https://code.sololearn.com/cnLyV6RrU5cf/?ref=app

30th Jan 2018, 5:23 PM
JMQ
JMQ - avatar
8 Answers
+ 13
thanks @kurwus and @lion
30th Jan 2018, 9:13 PM
JMQ
JMQ - avatar
+ 12
It should output -1. It does output -1, but only after 2 characters that I cant explain.
30th Jan 2018, 6:30 PM
JMQ
JMQ - avatar
+ 12
@Vlad I figured it must have been a Sololearn problem. Thanks for clearing it up (Im away from my laptop). And yes, Im on K&R2 ✌
30th Jan 2018, 8:09 PM
JMQ
JMQ - avatar
+ 3
Weird. But I can tell you this: It's a SoloLearn problem. Your code works fine on gcc and outputs - 1 as it should. Keep using K&R (hopefully K&R2) though. It's a great book. @Maged Characters are numbers. Wether they are 8-bit ASCII encoded or 16-bit Unicode or anything. Characters are numbers. And the end of file is a character. Ergo, the end of file is a number. In Unix systems, and thus in C, end of file is a number (-1). The following line exists somewhere in stdio.h: #define EOF -1
30th Jan 2018, 8:02 PM
Vlad Serbu
Vlad Serbu - avatar
+ 3
yeah, as kurwius says, the space before %d in the format string is not really a space, delete it and type it again and the weird should go away. It seems something weird creeps in text copied and pasted here on SL, I've seen it before, even had unexplainable compiler errors because of this.
30th Jan 2018, 8:59 PM
lion
lion - avatar
+ 1
i know that EOF means end of file so i dont think that it will show you any numbers i didn't understand what you are trying to output on the screen
30th Jan 2018, 6:07 PM
Maged Shakour
Maged Shakour - avatar
0
Cool thanx alot @Vlad serbu
30th Jan 2018, 8:11 PM
Maged Shakour
Maged Shakour - avatar
0
Where is the webpage?
31st Jan 2019, 5:26 PM
Innzam