eof

Value of EOF under windows

邮差的信 提交于 2020-08-25 21:12:57
问题 I wrote this code : #include <stdio.h> int main() { int c; while ((c = getchar()) != EOF) putchar(c); return 0; } Under windows, I figured out that I have to input ctrl+z so I can stop the program, I also printed the value of EOF and it's -1. However, when I enter -1 instead of ctrl+z the program continues to execute, and I want to understand why. Thank you! 回答1: Entering "-1" as text does not return the integer value -1 but two characters, i.e. a '-' (which corresponds to ASCII value 45 )

Node.js multiline input

人走茶凉 提交于 2020-08-24 05:56:46
问题 I'd like to prompt the user for input, let the user enter multiple lines of text, hitting enter between each line, then terminate the input by pressing CTRL+D or some such thing. With "keypress", I can catch the EOF, but I would have to handle all the echoing, backspace handling, terminal escape sequences, etc. manually. It would be much better if I could use "readline", but somehow intercept the CTRL+D (EOF) with "keypress", but I'm not sure how I would go about that. 回答1: You can use the

Go failing - expected 'package', found 'EOF'

浪尽此生 提交于 2020-06-09 09:25:08
问题 I've been having a hard time trying to execute a simple golang program in a virtual machine powered by vagrant. These are the relevant fields of my go env : GOARCH="amd64" GOPATH="/usr/local/src/go" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" This is the program I'm trying to execute ( located in /usr/local/src/go/program ): package program import ( "fmt" ) func main() { fmt.Print("Aloha") } This, the output that I get: main.go:4:5: /usr/local/go/src/fmt/doc.go:1:1:

feof和EOF的字符被重复读取问题的思考

孤者浪人 提交于 2020-02-28 23:06:24
void main() { PNode pNode; FILE *fp=fopen("1.txt","r"); pNode=Create(i); while(getc(fp)!=EOF) { int i; fscanf(fp,"%d",&i); pNode=Add(i,pNode); } fclose(fp); Print(pNode); } (问题源码如上所示) 问题介绍 我在温习C语言时,准备尝试编写单链表的结构,但是写到上面一段代码,运行后发现,文件的最后一个字符被重复读取了,焦头烂脑思考了一会儿,并且尝试搜集资料,写了这个博客。 问题思考 这个问题根源在文件读取上,因为我尝试了直接向链表中添加数据是没有任何问题的。而本程序使用了两个文件读取函数,即getc和fscanf,这两个函数的交错使用在一定程度上是程序结构有点混乱,这可能是我当时编程的时候没有用心思考造成的。 如果文件自身没有设置EOF的话,我们的getc函数遇到'\0'之后,将设置为EOF,再进入循环体一次,而fscanf已经读取不到有效字符了,因此返回EOF,但是此时i的值仍为最后一个整数的值,因此将再次读取该值。如果将下面一句 getc(fp)!=EOF 改为!feof(fp),则问题仍会出现,原因同上。 代码解决之道 正确的做法应该是下面一段代码: PNode pNode; //从文件中读取数据并添加到链表中

IntelliJ IDEA: send EOF symbol to Java application

时间秒杀一切 提交于 2020-01-31 06:09:00
问题 When running a command-line Java application from IntelliJ IDEA, is it possible to send EOF symbol to the program awaiting input? In console this can be done using ctrl-d combination but in IDEA it doesn't work. 回答1: It's been implemented, use Ctrl+D / ⌘+D on Mac. https://www.jetbrains.com/idea/help/debug-tool-window-console.html 回答2: In Dec 2012, it was still not possible : http://devnet.jetbrains.com/thread/436131 来源: https://stackoverflow.com/questions/16484297/intellij-idea-send-eof