eof

Why do I require multiple EOF (CTRL+Z) characters?

别来无恙 提交于 2019-11-26 09:55:25
问题 As a little background, I am quite new to the C Programming Language and as such have been attempting to work through some of the exercises in the second edition of the Kernighan & Ritchie manual. I do realize that I could probably deal with certain issues more succinctly by utilizing the standard library more, but am trying to keep my repertoire of useful commands in sync with the book as much as possible. If it makes a difference, I am compiling my source in a Windows XP environment using

Comparing unsigned char and EOF

眉间皱痕 提交于 2019-11-26 09:52:26
问题 when the following code is compiled it goes into an infinite loop: int main() { unsigned char ch; FILE *fp; fp = fopen(\"abc\",\"r\"); if(fp==NULL) { printf(\"Unable to Open\"); exit(1); } while((ch = fgetc(fp))!=EOF) printf(\"%c\",ch); fclose(fp); printf(\"\\n\",ch); return 0; } The gcc Compiler also gives warning on compilation abc.c:13:warning: comparison is always true due to limited range of data type the code runs fine when unsigned char is replaced by char or int as expected i.e. it

How to signify no more input for string ss in the loop while (cin >> ss)

一曲冷凌霜 提交于 2019-11-26 09:51:27
问题 I used \"cin\" to read words from input stream, which like int main( ){ string word; while (cin >> word){ //do sth on the input word } // perform some other operations } The code structure is something like the above one. It is compilable. During the execution, I keep inputting something like aa bb cc dd My question is how to end this input? In other words, suppose the textfile is just \"aa bb cc dd\". But I do not know how to let the program know that the file ends. 回答1: Your code is correct

fgetc, checking EOF

僤鯓⒐⒋嵵緔 提交于 2019-11-26 08:28:42
问题 In the book Linux System Programming I have read some like this: fgetc returns the character read as an unsigned char cast to an int or EOF on end of file or error. A common error using fgetc is: char c; if ((c = fgetc()) != EOF) {...} The right version of this code is: int c; if ((c = fgetc()) != EOF) { printf(\"%c\", (char)c); ... } So, why can\'t I cast a return value to char before comparing with EOF ? Why do I have to compare EOF exactly with int ? As EOF defined as -1 , isn\'t it

ctrl-d didn't stop the while(getchar()!=EOF) loop [duplicate]

江枫思渺然 提交于 2019-11-26 08:26:26
问题 This question already has an answer here: Canonical vs. non-canonical terminal input 1 answer Here is my code. I run it in ubuntu with terminal. when I type (a Ctrl D ) in terminal, the program didn\'t stop but continued to wait for my input. Isn\'t Ctrl D equal to EOF in unix? Thank you. #include<stdio.h> main() { int d; while(d=getchar()!=EOF) { printf(\"\\\"getchar()!=EOF\\\" result is %d\\n\", d); printf(\"EOF:%d\\n\", EOF); } printf(\"\\\"getchar()!=EOF\\\" result is %d\\n\", d); } 回答1:

EOF in Windows command prompt doesn&#39;t terminate input stream

老子叫甜甜 提交于 2019-11-26 06:46:22
问题 Code: #include <stdio.h> #define NEWLINE \'\\n\' #define SPACE \' \' int main(void) { int ch; int count = 0; while((ch = getchar()) != EOF) { if(ch != NEWLINE && ch != SPACE) count++; } printf(\"There are %d characters input\\n\" , count); return 0; } Question: Everything works just fine, it will ignore spaces and newline and output the number of characters input to the screen (in this program I just treat comma, exclamation mark, numbers or any printable special symbol character like

Can we write an EOF character ourselves?

别等时光非礼了梦想. 提交于 2019-11-26 04:48:56
问题 Most of the languages like C++ when writing into a file, put an EOF character even if we miss to write statements like : filestream.close However is there any way, we can put the EOF character according to our requirement, in C++, for an instance. Or any other method we may use apart from using the functions provided in C++. If you need to ask more of information then kindly do give a comment. Thanks in advance. EDIT: Thanks for your support but here\'s an addition to this question: What if,

Python unexpected EOF while parsing

霸气de小男生 提交于 2019-11-26 04:32:54
Here's my python code. Could someone show me what's wrong with it. while 1: date=input("Example: March 21 | What is the date? ") if date=="June 21": sd="23.5° North Latitude" if date=="March 21" | date=="September 21": sd="0° Latitude" if date=="December 21": sd="23.5° South Latitude" if sd: print sd And Here's what happens: >>> Example: March 21 | What is the date? Traceback (most recent call last): File "C:\Users\Daniel\Desktop\Solar Declination Calculater.py", line 2, in <module> date=input("Example: March 21 | What is the date? ") File "<string>", line 0 ^ SyntaxError: unexpected EOF while

Python 3: EOF when reading a line (Sublime Text 2 is angry)

半腔热情 提交于 2019-11-26 04:26:47
问题 while True: reply = input(\'Enter text\') if reply == \'stop\': break print(reply.upper()) The result was: Enter text:Traceback (most recent call last): File \"C:\\PythonProjects\\5.py\", line 2, in <module> reply = input(\'Enter text:\') EOFError: EOF when reading a line [Finished in 0.2s with exit code 1] It is only in Sublime Text 2. I tried IDLE, tried command line, everything is perfect. Why should Subleme shout at me? By the way, maybe you could also explain my what EOF may mean in such

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

旧城冷巷雨未停 提交于 2019-11-26 04:07:18
问题 I have a text file that has strings on each line. I want to increment a number for each line in the text file, but when it reaches the end of the file it obviously needs to stop. I\'ve tried doing some research on EOF, but couldn\'t really understand how to use it properly. I\'m assuming I need a while loop, but I\'m not sure how to do it. 回答1: How you detect EOF depends on what you're using to read the stream: function result on EOF or error -------- ---------------------- fgets() NULL