Can we write an EOF character ourselves?

There is no EOF character. EOF by definition “is unequal to any valid character code”. Often it is -1. It is not written into the file at any point. There is a historical EOF character value (CTRL+Z) in DOS, but it is obsolete these days. To answer the follow-up question of Apoorv: The OS never …

Read more

How to use EOF to run through a text file in C?

How you detect EOF depends on what you’re using to read the stream: function result on EOF or error ——– ———————- fgets() NULL fscanf() number of succesful conversions less than expected fgetc() EOF fread() number of elements read less than expected Check the result of the input call for the appropriate condition above, then call …

Read more

Vim show newline at the end of file

‘endofline’ is on by default so you don’t need it in your ~/.vimrc. EOL or “newline” doesn’t mean “there’s an empty line after here”, it means “this marks the end of the line, any further characters are to be displayed on another line”. “newline” != “new line”. The last line of your file is #21 …

Read more

What is value of EOF and ‘\0’ in C

EOF is a macro which expands to an integer constant expression with type int and an implementation dependent negative value but is very commonly -1. ‘\0′ is a char with value 0 in C++ and an int with the value 0 in C. The reason why printf(“%d”,a==EOF); resulted in 1 was because you didn’t assign …

Read more

How does ifstream’s eof() work?

-1 is get‘s way of saying you’ve reached the end of file. Compare it using the std::char_traits<char>::eof() (or std::istream::traits_type::eof()) – avoid -1, it’s a magic number. (Although the other one is a bit verbose – you can always just call istream::eof) The EOF flag is only set once a read tries to read past the …

Read more

What is EOF in the C programming language?

On Linux systems and OS X, the character to input to cause an EOF is Ctrl–D. For Windows, it’s Ctrl–Z. Depending on the operating system, this character will only work if it’s the first character on a line, i.e. the first character after an Enter. Since console input is often line-oriented, the system may also …

Read more

Checking for an empty file in C++

Perhaps something akin to: bool is_empty(std::ifstream& pFile) { return pFile.peek() == std::ifstream::traits_type::eof(); } Short and sweet. With concerns to your error, the other answers use C-style file access, where you get a FILE* with specific functions. Contrarily, you and I are working with C++ streams, and as such cannot use those functions. The above code …

Read more

PHP using Gettext inside

As far as I can see in the manual, it is not possible to call functions inside HEREDOC strings. A cumbersome way would be to prepare the words beforehand: <?php $world = _(“World”); $str = <<<EOF <p>Hello</p> <p>$world</p> EOF; echo $str; ?> a workaround idea that comes to mind is building a class with a …

Read more