eof

How do I recognize EOF in Java Sockets?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-19 04:54:05
问题 I want to recognize end of data stream in Java Sockets. When I run the code below, it just stuck and keeps running (it stucks at value 10 ). I also want the program to download binary files, but the last byte is always distinct, so I don't know how to stop the while (pragmatically). String host = "example.com"; String path = "/"; Socket connection = new Socket(host, 80); PrintWriter out = new PrintWriter(connection.getOutputStream()); out.write("GET "+ path +" HTTP/1.1\r\nHost: "+ host +"\r\n

EOF exercise 1-6 K&R The C programming language

假装没事ソ 提交于 2019-12-19 04:06:02
问题 This is taken directly from the K&R book: The precedence of != is higher than that of = , which means that in the absence of parentheses the relational test != would be done before the assignment = . So the statement c = getchar() != EOF is equivalent to c = (getchar() != EOF) This has the undesired effect of setting c to 0 or 1, depending on whether or not the call of getchar returned end of file. (More on this in Chapter 2.) Exercise 1-6. Verify that the expression getchar() != EOF is 0 or

Why two EOF needed as input? [duplicate]

Deadly 提交于 2019-12-18 07:06:29
问题 This question already has an answer here : Canonical vs. non-canonical terminal input (1 answer) Closed 4 years ago . When I run the code below, I use three inputs (in Ubuntu terminal): abc(Ctrl+D)(Ctrl+D) abc(Ctrl+D)(Enter)(Ctrl+D) abc(Enter)(Ctrl+D) The code reacts well in all cases. My question is: why in 1) and 2) I need two EOF? #include <iostream> int main() { int character; while((character=std::cin.get())!=EOF){} std::cout << std::endl << character << std::endl; } 回答1: That's how the

fseek on a position beyond EOF does not trigger EOF using feof, how come?

China☆狼群 提交于 2019-12-18 04:04:12
问题 I'm reading data from a file to memory that is opened with: FILE *f = fopen(path, "rb"); Before I start copying bytes from the file I seek to a start position using: /** * Goes to the given position of the given file. * * - Returns 0 on success * - Returns -1 on EOF * - Returns -2 if an error occured, see errno for error code * - Returns -3 if none of the above applies. This should never happen! */ static int8_t goto_pos(FILE *f, uint64_t pos) { int err = fseek(f, pos, SEEK_SET); if (err != 0

Match from pattern to end of file in bash

☆樱花仙子☆ 提交于 2019-12-17 21:05:36
问题 I have been trying to figure out how to use grep in a bash script to match from a pattern to the end of the file. The file is not always the same number of lines each time and is not always [A-Za-z0-9] . I'm trying to migrate from a flat-file based catalog to a database. File excerpt: First, Last: Doe, John ID: xxxxxxxx ... Case Notes: This "person" does not exist! Please do not add him. Thanks. I need to grab everything from Case Notes: to the end of file. I can't seem to find anything to

How to use feof(FILE *f)?

那年仲夏 提交于 2019-12-17 16:53:39
问题 I'm having a hard time with a do-while loop, that is supposed to stop when we reach the end of the file. Here's the loop code: do { if (pcompanyRow[0] != '#' && pass == 1) { strtok(pcompanyRow, ":"); pcompanyName = strcpy(pcompanyName, strtok(NULL, "")); pass = 2; fgets(pcompanyRow, 1024, f); } if (pcompanyRow[0] != '#' && pass == 2) { strtok(pcompanyRow, ":"); pcompanySMSPrice = strcpy(pcompanySMSPrice, strtok(NULL , "")); pass = 3; fgets(pcompanyRow, 1024 , f); } if (pcompanyRow[0] != '#' &

Why Ctrl-Z does not trigger EOF?

喜你入骨 提交于 2019-12-17 09:57:52
问题 Why Ctrl + Z does not trigger the loop to finish on the following small program? #include <stdio.h> main() { int c; while ((c = getchar()) != EOF) { //nothing } return 0; } If I enter: test^ZEnter , it does not get out of the loop. I found related questions around (here and here) but none to explain it for C (not C++) under Windows. Note : I use Visual Studio 2015 PRE on a windows 8.1 回答1: You need to hit Enter and then use ctrl + Z and then Enter again. or, you may also use F6 回答2: EOF like

How to find out whether a file is at its `eof`?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 04:59:03
问题 fp = open("a.txt") #do many things with fp c = fp.read() if c is None: print 'fp is at the eof' Besides the above method, any other way to find out whether is fp is already at the eof? 回答1: fp.read() reads up to the end of the file, so after it's successfully finished you know the file is at EOF; there's no need to check. If it cannot reach EOF it will raise an exception. When reading a file in chunks rather than with read() , you know you've hit EOF when read returns less than the number of

What is value of EOF and '\0' in C

筅森魡賤 提交于 2019-12-17 04:53:11
问题 I know that EOF and '\0' are of type integers, but if so shouldn't they have a fixed value? I printed both and got -1 for EOF and 0 for '\0' . But are these values fixed? I also had this int a=-1; printf("%d",a==EOF); //printed 1 Are the value for EOF and '\0' fixed integers? 回答1: 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

What is value of EOF and '\0' in C

对着背影说爱祢 提交于 2019-12-17 04:53:03
问题 I know that EOF and '\0' are of type integers, but if so shouldn't they have a fixed value? I printed both and got -1 for EOF and 0 for '\0' . But are these values fixed? I also had this int a=-1; printf("%d",a==EOF); //printed 1 Are the value for EOF and '\0' fixed integers? 回答1: 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