eof

Why is this load function only grabbing the first thing in the file?

两盒软妹~` 提交于 2019-12-08 14:14:05
问题 I know this has something to do with eof, but I don't know how streams work exactly, i'd understand better if someone could tell me whats going on. say I have 3 numbers {1, 2, 3} the load function puts the variables into the nodes, but when I go to print all the nodes only 1 will print. void load() { ifstream fload; node *n = new node; node *temp = new node; fload.open("DoubleList.dat"); if (fload) { fload >> n->data; n->next = NULL; n->prev = NULL; head = n; tail = n; curr = n; while (!fload

Docker-Python script input error

主宰稳场 提交于 2019-12-08 12:20:40
问题 I am new to Docker.I have a script named ApiClient.py. The ApiClient.py script asks the user to input some data such as user's email,password,the input file(where the script will get some input information) and the output file(where the results will be output).I have used this Dockerfile: FROM python:3 WORKDIR /Users/username/Desktop/Dockerfiles ADD . /Users/username/Desktop/Dockerfiles RUN pip install --trusted-host pypi.python.org -r requirements.txt EXPOSE 80 ENV NAME var_name CMD ["python

Handling SIGCHLD will return EOF to the father, why?

岁酱吖の 提交于 2019-12-08 08:08:21
问题 I have a small shell that creates children (with fork()) and make them execute some commands with execvp. It support also the & option so the father can run other commands in the meanwhile. When a child die i want to write that on the console and also the child pid, so i defined a sighandler for SIGCHLD: void backdeadchild(int sig) { int pid, exitstat; pid = wait(&exitstat); printf("Child with pid: %d died", pid); } The problem is that after the handler prints the message also the father

StreamReader ReadLine returns null when not EOF

谁说胖子不能爱 提交于 2019-12-08 06:26:26
Having a strange problem that I've never encountered nor heard of happening. It seems that occasionally, the ReadLine() function of the StreamReader class will return NULL, as if it's at the end of the file, BUT it's not. My log file indicates that everything is happening just as if it had actually reached the end of the file, but yet it's only processing part of it. There doesn't appear to be any consistency, because if I restart the process from scratch, the whole file is processed without incident. Clearly, there is nothing funky in the file itself, or it would do this on the same line each

C - read scanf until feof(stdin), don't output error

爱⌒轻易说出口 提交于 2019-12-08 06:11:47
问题 I am using the scanf() function in my program to scan an integer. The way I am doing it is: while (!feof (stdin)) if (scanf("%d", &height) != 1) { puts("Wrong input!"); return 1; } The problem is, that after actually doing EOF, I get the wrong input and return 1, due to the scanf not returning 1. How should I solve this issue? 回答1: As the documentation for scanf states, it will return the number of items successfully matched and assigned. This can be the number of items you gave if completely

StreamReader ReadLine returns null when not EOF

…衆ロ難τιáo~ 提交于 2019-12-08 05:38:05
问题 Having a strange problem that I've never encountered nor heard of happening. It seems that occasionally, the ReadLine() function of the StreamReader class will return NULL, as if it's at the end of the file, BUT it's not. My log file indicates that everything is happening just as if it had actually reached the end of the file, but yet it's only processing part of it. There doesn't appear to be any consistency, because if I restart the process from scratch, the whole file is processed without

read strings from input till EOF

别来无恙 提交于 2019-12-08 02:49:48
问题 I have gone through many posts on SO , but still i am not able to resolve the issue . I have to read : text pattern1 pattern2 from standard input , there are many text and patterns . Code : string t,p1,p2; while(getline(cin, t)) { cin>>p1; cin>>p2; cout<<"text is = "<<t<<"\np1 is = "<<p1<<"\np2 is = "<<p2<<endl; } Input file : hammer ham mer gogoa go z gogoa g o Output : text is = hammer p1 is = ham p2 is = mer text is = p1 is = gogoa p2 is = go text is = p1 is = z p2 is = gogoa text is = p1

istream::peek curious behavior wrt. EOF

依然范特西╮ 提交于 2019-12-08 02:07:29
问题 I've just encountered a curious situation in C++. I was doing something like: istream in; // ... in.get(); // get a char (which turns out to be the last) // curiously ios::eof bit doesn't get set just yet c = in.peek(); // attempt to peek, return EOF and now set ios::eof bit if(c == EOF) { // realize shouldn't have gotten the last char for some reason in.unget(): // attempt to unget, *fails* (because ios:eof bit was set) } Now I'm curious why peek sets the eof bit; I find this highly

confused by control flow execution in C++ Primer example

删除回忆录丶 提交于 2019-12-08 01:24:32
问题 I am going through C++ Primer (5th ed). In section 1.4.4, there is the following example: #include <iostream> int main() { // currVal is the number we're counting; we'll read new values into val int currVal = 0, val = 0; // read first number and ensure that we have data to process if (std::cin >> currVal) { int cnt = 1; // store the count for the current value we're processing while (std::cin >> val) { // read the remaining numbers if (val == currVal) // if the values are the same ++cnt; //

Send command and exit using python pty pseudo terminal process

人盡茶涼 提交于 2019-12-07 17:32:06
问题 Using python pty module, i want to send some commands to the terminal emulator, using a function as stdin (as pty module wants), and then force quitting. I thought about something like import pty cmnds = ['exit\n', 'ls -al\n'] # Command to send. I try exiting as last command, but it doesn't works. def r(fd): if cmnds: cmnds.pop() # It seems is not executing sent commands ('ls -al\n') else: # Can i quit here? Can i return EOF? pass pty.spawn('/bin/sh', r) Thank you 回答1: Firstly, the pty module