eof

C++: .eof on an empty file

半腔热情 提交于 2019-12-21 05:45:09
问题 Lets see this program: ifstream filein("hey.txt"); if(filein.eof()){ cout<<"END"<<endl; } Here "hey.txt" is empty. So the if condition here is thought should have been true But it isnt Why isnt the eof returning true although the file is empty? If i added this before the if the eof returns true although arr is still empty and the file is still empty so both unchanged char arr[100]; filein.getline(arr,99); 回答1: eof() function returns "true" after the program attempts to read past the end of

Using Antlr for parsing data from never-ending stream

空扰寡人 提交于 2019-12-21 04:42:21
问题 Is Antlr suitable for parsing data from streams that don't have EOF right after the text to parse? According to my observation, the lexer does not emit the current token until the first character of next token is received. On top of that - the parser seems not to emit the rule until the first token of next rule is received. Here is a simple grammar I tried: fox: 'quick' 'brown' 'fox' '\r'? '\n' ; Then I used the generated parser with UnbufferedCharStream and UnbufferedTokenStream: CharStream

Prevent FIFO from closing / reuse closed FIFO

时光总嘲笑我的痴心妄想 提交于 2019-12-20 11:44:11
问题 Consider the following scenario: a FIFO named test is created. In one terminal window (A) I run cat <test and in another (B) cat >test . It is now possible to write in window B and get the output in window A. It is also possible to terminate the process A and relaunch it and still be able to use this setup as suspected. However if you terminate the process in window B, B will (as far as I know) send an EOF through the FIFO to process A and terminate that as well. In fact, if you run a process

Vim no end of line on last line or eof

核能气质少年 提交于 2019-12-20 08:58:14
问题 I am trying to setup vim to skip adding eol on last line or eof, i have tried this :set binary :set noeol :w which is not perfect cause binary override filetype for later use. Any other option to set this, i don't need newline on last line. 回答1: I wanted to add an answer that I think can be as useful. The selected answer always remove the EOL on files even if they had one to begin with. This may be the behavior that you want, it also may not be. In my opinion I want to preserve the EOL as I

Write an EOF to a pipe

一个人想着一个人 提交于 2019-12-20 05:21:54
问题 I have a parent and a child prozess and want to write an EOF from the parent to the child via a pipe... how does this work? here is my attampt: ---parent code--- if(dup2(parent_pipe[1], STDOUT_FILENO) == -1) { /*stdout gets closed and parent_pipe is duplicated with id of stdout*/ error("Can't duplicate the write-end of the pipe to stdout!"); } if(close(parent_pipe[0]) == -1) { error("Can't close read-end of the pipe!"); } char blub[] = "EOF"; if(write(parent_pipe[1], blub, strlen(blub)) == -1

C++ eof() problem - never returns true?

旧时模样 提交于 2019-12-20 04:31:46
问题 So I'm trying to read this file. Everything looks like it should work, but during runtime the program times out and stops working, and I have to close it. What is going on? I suspect that the oef() test is never returning true and it keeps looking for more in the file. I have no dragging empty lines in the text file. I've tried debugging this like crazy. I can't find anything wrong but it still refuses to work. Pet** petArray; ifstream textFile2; textFile2.open("pets.txt"); int i = 0; string

How to solve an EOF error when reading a binary file

十年热恋 提交于 2019-12-20 03:13:40
问题 class CarRecord: # declaring a class without other methods def init (self): # constructor self .VehicleID = "" self.Registration = "" self.DateOfRegistration = None self.EngineSize = 0 self.PurchasePrice = 0.00 import pickle # this library is required to create binary f iles ThisCar = CarRecord() Car = [ThisCar for i in range (100)] CarFile = open ('Cars.DAT', 'wb') # open file for binary write for i in range (100) : # loop for each array element pickle.dump (Car[i], CarFile) # write a whole

Bash here document produces no output, any idea why?

我是研究僧i 提交于 2019-12-20 02:44:39
问题 On my Acer 725 with Lubuntu 13.04 this little script: #!/bin/bash echo "======" echo <<xxxxx aaaaaaaaaqqqqqqqqq xxxxx echo "======" produces this output: ====== ====== It should produce this: ====== aaaaaaaaaqqqqqqqqq ====== I've searched all over for a reason but I can't find anything. I have a horrible feeling that I am missing something embarrassingly obvious. Any ideas? 回答1: I have a horrible feeling that I am missing something embarrassingly obvious. Use cat instead of echo : cat <<xxxxx

How to stimulate EOF without preceding newline in C

丶灬走出姿态 提交于 2019-12-19 11:52:10
问题 Lets say I have the below C code: int getLine (char line[]) { int c, i=0; while( (c=getchar()) != EOF ) line[i++]=c; line[i++] = c; return i; } >> Enter: 007 >> ^Z >> Output: If we closely observe the way I give output above, I am pressing Enter before stimulating EOF. This means, the length of string is 4 not 3 (excluding EOF). When I am doing my exercises, I am really facing some trouble with that extra \n. How do I stimulate EOF without newline? Is it possible at all? >> Enter: 007^Z >> ^Z

Why do I need to press CTRL+D twice to break out of `while ((c=getchar())!=EOF)` in Ubuntu 14.10?

独自空忆成欢 提交于 2019-12-19 10:21:54
问题 I am new to C Programming and Ubuntu. I was reading the "The C Programming Language" by D.M Ritchie where I found the following code: #include <stdio.h> int main() { int c; int nc=0; while((c = getchar()) != EOF) { nc++; } printf("%d Characters \n",nc); return 0; } But while running the program I enter "Hello" ,then CTRL+D twice to get the actual number of characters which is 5. But when I enter "Hello" then CTRL+D once , nothing happens, the terminal still waits for input. Why? 回答1: Quoting