eof

End of File in stdin

跟風遠走 提交于 2019-11-27 04:41:28
问题 A question about this has been asked here End of File (EOF) in C but it still doesn't completely solve my problem. EOF makes sense to me in any datastream which is not stdin , for example if I have some data.txt file, fgetc() will read all the chars and come to the end of file and return -1 . What I don't understand is the concept of EOF in stdin . If I use getchar() , it will wait for me to enter something, so if there is NOTHING written, End of File, ( EOF ) is not returned automatically?

Representing EOF in C code?

南楼画角 提交于 2019-11-27 03:58:59
问题 The newline character is represented by "\n" in C code. Is there an equivalent for the end-of-file (EOF) character? 回答1: EOF is not a character (in most modern operating systems). It is simply a condition that applies to a file stream when the end of the stream is reached. The confusion arises because a user may signal EOF for console input by typing a special character (e.g Control-D in Unix, Linux, et al ), but this character is not seen by the running program, it is caught by the operating

Reaching EOF with fgets

泄露秘密 提交于 2019-11-27 03:29:49
问题 I'm writing a function that perform some authentications actions. I have a file with all the user_id:password:flag couples structured like this: Users.txt user_123:a1b2:0 user_124:a2b1:1 user_125:a2b2:2 This is the code: int main(){ /*...*/ /*user_id, password retrieving*/ USRPSW* p = malloc(sizeof(USRPSW)); if(p == NULL){ fprintf(stderr, "Dynamic alloc error\n"); exit(EXIT_FAILURE); } memset((void*)p, 0, sizeof(USRPSW)); if(usr_psw_read(acc_sock_ds, p->user_id, USR_SIZE) <= 0){ printf(

Comparing unsigned char and EOF

末鹿安然 提交于 2019-11-27 02:01:50
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 terminates. But the code also runs fine for unsigned int as well. as i have i have read in EOF is defines as -1 in

How to loop until EOF in Python?

故事扮演 提交于 2019-11-27 00:48:38
问题 I need to loop until I hit the end of a file-like object, but I'm not finding an "obvious way to do it", which makes me suspect I'm overlooking something, well, obvious. :-) I have a stream (in this case, it's a StringIO object, but I'm curious about the general case as well) which stores an unknown number of records in "<length><data>" format, e.g.: data = StringIO("\x07\x00\x00\x00foobar\x00\x04\x00\x00\x00baz\x00") Now, the only clear way I can imagine to read this is using (what I think

PHP using Gettext inside <<<EOF string

风流意气都作罢 提交于 2019-11-27 00:46:24
问题 I use PHP's EOF string to format HTML content without the hassle of having to escape quotes etc. How can I use the function inside this string? <?php $str = <<<EOF <p>Hello</p> <p><?= _("World"); ?></p> EOF; echo $str; ?> 回答1: As far as I can see in the manual, it is not possible to call functions inside HEREDOC strings. A cumbersome way would be to prepare the words beforehand: <?php $world = _("World"); $str = <<<EOF <p>Hello</p> <p>$world</p> EOF; echo $str; ?> a workaround idea that comes

Exiting a while loop at EOF using scanf in C

旧时模样 提交于 2019-11-26 23:47:19
问题 I'm writing a few very small programs for my introductory C course. One of them requires me to read in double values, one number per line, and then print out basic statistics after EOF. Here is my the segment of my code that is giving me issues: double sample[1000000]; int result; double number; int i = 0; int count = 0; double sum = 0; double harmosum = 0; result = scanf(" %lf \n", &number); double min = number; double max = number; while(result != EOF){ sample[i] = number; if(number < min){

fgetc, checking EOF

末鹿安然 提交于 2019-11-26 22:54:12
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 normally casted to char ? Are there platforms/compilers where it is not true? Cacho Santa You can't cast the

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

无人久伴 提交于 2019-11-26 22:47:10
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); } EOF is not a character. The EOF is a macro that getchar() returns when it reaches the end of input or encounters some kind of

SyntaxError: unexpected EOF while parsing

江枫思渺然 提交于 2019-11-26 22:46:04
问题 I am getting error while running this part of the code. tried some of the existing solutions, none of them helped elec_and_weather = pd.read_csv(r'C:\HOUR.csv', parse_dates=True,index_col=0) # Add historic DEMAND to each X vector for i in range(0,24): elec_and_weather[i] = np.zeros(len(elec_and_weather['DEMAND'])) elec_and_weather[i][elec_and_weather.index.hour==i] = 1 # Set number of hours prediction is in advance n_hours_advance = 24 # Set number of historic hours used n_hours_window = 24