eof

How to know if the next character is EOF in C++

你说的曾经没有我的故事 提交于 2019-11-28 08:35:57
I'm need to know if the next char in ifstream is the end of file. I'm trying to do this with .peek() : if (file.peek() == -1) and if (file.peek() == file.eof()) But neither works. There's a way to do this? Edit: What I'm trying to do is to add a letter to the end of each word in a file. In order to do so I ask if the next char is a punctuation mark, but in this way the last word is left without an extra letter. I'm working just with char , not string . istream::peek() returns the constant EOF (which is not guaranteed to be equal to -1) when it detects end-of-file or error . To check robustly

Java heap dump error with jmap command : Premature EOF

柔情痞子 提交于 2019-11-28 07:13:36
问题 I have encountered below exception during execution of below command jmap -dump:format=b,file=heap_dump.bin <process_id> output: Dumping heap to <file_name> Exception in thread "main" java.io.IOException: Premature EOF at sun.tools.attach.HotSpotVirtualMachine.readInt(HotSpotVirtualMachine.java:248) at sun.tools.attach.LinuxVirtualMachine.execute(LinuxVirtualMachine.java:199) at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:217) at sun.tools.attach

How do you read scanf until EOF in C?

本秂侑毒 提交于 2019-11-28 06:47:00
I have this but once it reaches the supposed EOF it just repeats the loop and scanf again. int main(void) { char words[16]; while(scanf("%15s", words) == 1) printf("%s\n", words); return 0; } Try: while(scanf("%15s", words) != EOF) You need to compare scanf output with EOF Since you are specifying a width of 15 in the format string, you'll read at most 15 char. So the words char array should be of size 16 ( 15 +1 for null char). So declare it as: char words[16]; Scanf is pretty much always more trouble than it's worth. Here are two better ways to do what you're trying to do. This first one is

PHP using Gettext inside <<<EOF string

岁酱吖の 提交于 2019-11-28 05:13:51
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; ?> 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 to mind is building a class with a magic getter method . You would declare a class like this: class

How to loop until EOF in Python?

那年仲夏 提交于 2019-11-28 05:07:51
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 of as) an initialized loop, which seems a little un-Pythonic: len_name = data.read(4) while len_name !=

How to process huge text files that contain EOF / Ctrl-Z characters using Python on Windows?

﹥>﹥吖頭↗ 提交于 2019-11-28 03:42:41
问题 I have a number of large comma-delimited text files (the biggest is about 15GB) that I need to process using a Python script. The problem is that the files sporadically contain DOS EOF (Ctrl-Z) characters in the middle of them. (Don't ask me why, I didn't generate them.) The other problem is that the files are on a Windows machine. On Windows, when my script encounters one of these characters, it assumes it is at the end of the file and stops processing. For various reasons, I am not allowed

Exiting a while loop at EOF using scanf in C

╄→гoц情女王★ 提交于 2019-11-28 02:26:26
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){ min = number; } if(number > max){ max = number; } sum += number; if(number != 0){ harmosum += (1 /

How to read user input until EOF in python?

喜夏-厌秋 提交于 2019-11-28 01:38:23
问题 I came across this problem in UVa OJ. 272-Text Quotes Well, the problem is quite trivial. But the thing is I am not able to read the input. The input is provided in the form of text lines and end of input is indicated by EOF. In C/C++ this can be done by running a while loop: while( scanf("%s",&s)!=EOF ) { //do something } How can this be done in python .? I have searched the web but I did not find any satisfactory answer. Note that the input must be read from the console and not from a file.

Having troubles with EOF on Windows 7

为君一笑 提交于 2019-11-28 01:30:02
I'm currently learning C with K&R and I'm having a hard time sending EOF simulation through cmd. I was trying Ctrl + Z which did nothing. In some cases Enter is doing the work and in other cases nothing does it. Thanks in advance for any help. Assuming you're on Windows, the situation is that you basically have to do the ctrl + Z at the beginning of a line -- i.e., you have to have hit enter , then do the ctrl + Z , then (depending on how the input is being read) possibly enter again. You can also use F6 to signal the end of the input. At least in most cases, this will work even when/if it

End of File in stdin

我怕爱的太早我们不能终老 提交于 2019-11-27 23:44:46
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? So is it that only the user can invoke EOF in stdin by pressing Ctrl + Z ? If so then what are some of