FAQ Database Discussion Community


SageMathCloud: Error: unexpected EOF while parsing

python,eof,sage
In a Sage worksheet (.sagews file) in SageMathCloud, this code: def elgamal_encrypt ( pub_key ,g ,p , message ): k = floor ( 1+( p -2)* random ()) return ( Mod (g , p )^ k , message * Mod ( pub_key ^k , p ) ) produces the error:...

C code to read a text file does not find EOF (end of file)

c,text-files,infinite-loop,eof
I've wrote this short code to read a text file and copy its information to a new txt file, but doing some character substitution in the process. My problem is, the code does all the job it is supposed to do but it doesnt end. It cant find the EOF...

Bash error: “b.sh: line 52: syntax error: unexpected end of file logout”

osx,bash,ssh,scp,eof
So, I wanted this to download a file from my computer, transfer it to my iPhone, install the file there, and respring my phone. For some reason the error you saw in the title pops up. Would be nice if someone could help, thanks. #!/bin/bash clear cd downloads if [...

StreamTokenizer Behavior for division operator “/”

java,string,eof,stringreader
Take a look at the demo code for StreamTokenizer here. It doesn't seems to work properly when there is / in string(Just add / in between string in StringReader). Here is the code from mentioned link, StreamTokenizer tokenizer = new StreamTokenizer( new StringReader("Mary had 1 little lamb...")); while(tokenizer.nextToken() != StreamTokenizer.TT_EOF){...

How to make a Python interpreter for a webpage

php,python,eof
There might already be questions like this, but none of them answer my question. I have a script that loads a Python script in the directory and then displays a output with PHP: <?php $param1 = "first"; $param2 = "second"; $param3 = "third"; $command = "scripts/sg.py"; $command .= " $param1...

std::getline partially reads first and last line and sets eof-bit

c++,csv,eof,getline
I need to read csv-files with C++: the first line of the file contains all column titles, the remaining lines contain floating point data (examples below, files have been shrunk down). A few files have issues, I'm using the following code #include <iostream> #include <fstream> #include <string> // Compiled and...

File read gets EOF before real EOF

python,image,eof
I receive a file (*.png) via network and that file is written (in binary mode) to the HDD properly. When I try to open the file, for further manipulation, it won't load totally corrupting the lower part of the png image. This happens with several PNG files so it's not...

End while loop with ctrl+d, scanf?

c,while-loop,printf,scanf,eof
I want the user to be asked "how many circles" they wanna write until the user decides to end it with (Ctrl+d) which is EOF? extra question: if I write a letter for example "k" it will spam out circles. How do I change that? #include <stdio.h> int main ()...

Assign null string to gets

c,string,null,eof
I want to write a program in C that fills an array p[MAX][N] of strings I used this but i dont know which is the null string to enter when i give input. #include <stdio.h> #include <string.h> #define R 3 #define C 8 int main() { int i; char strings[R][C];...

Weird EOF behavior C++/VIM versus other IDEs

c++,vim,eof
I'm currently having problems with the EOF bit getting set correctly with my program. The requirements for this program states that I will have two files that both have sorted lists of integers. The program should take in a number from both files and then compare these numbers. If one...

try to delete LF in python or notepad++ but cannot use “find&replace” to find it by “\n”,

newline,eof
the picture is as the following: I don't know why I cannot locate the LF, so does CRLF! According to the image, there is exactly LF there, but I cannot use notepad++'s find function by "\n" to really find it, so I cannot replace it with blank at all. My...

How I can check if it something available in socket? [duplicate]

c,sockets,connect,eof,read-write
This question already has an answer here: How to check amount of data available for a socket in C and Linux 6 answers I write a simple application that provide connection between two computers in C. I have a problem with simultaneously reading and writing in socket. I am...

Saxon HE and XQuery: Unexpected token “

xquery,eof,saxon
I copy paste this example from http://www.w3schools.com/xquery/xquery_functions.asp (though I added the namespace declaration): declare namespace local="local"; declare function local:minPrice($p as xs:decimal?,$d as xs:decimal?) as xs:decimal? { let $disc := ($p * $d) div 100 return ($p - $disc) }; But when I try to run it, the SAXON output is:...

boost::asio::async_read() of stream_descriptor now returning EOF

ubuntu,c++11,boost-asio,eof
Upgraded Ubuntu today from 14.10 to 15.04. Now seeing different behaviour either in boost::asio::async_read(), boost::asio::posix::stream_descriptor, or tap/tun interfaces. Calling async_read() immediately returns boost::asio::error::eof. If I ignore the error and loop back up to start a new async_read() it does eventually read when bytes are available, and the application continues to...

what does rdstate() return value means?

c++,c++11,io,eof
istream& Read(istream &is) { std::string buf; while (is >> buf) { cout << is.eofbit << " " << is.failbit << " " << is.badbit << endl; cout << is.rdstate() << endl; cout << buf << endl; } cout << is.eofbit << " " << is.failbit << " " << is.badbit...

Writing my own Cat function in C

c,function,eof,cat,fgetc
Hi i don't know how to simulate my own Cat function in C, i know how it works when no arguments are set and i already get it, but my problem is when i tried to open a file and then print itself... my code until now: #include <stdio.h> #include...

Why two EOF needed as input? [duplicate]

c++,iostream,eof
This question already has an answer here: Canonical vs. non-canonical terminal input 1 answer 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?...

Ruby Count lines in file including last line(empty)

ruby,file,io,eof
I'm trying to count the lines of a file with ruby but I can't get either IO or File to count the last line. What do I mean by last line? Here's a screenshot of Atom editor getting that last line Ruby returns 20 lines, I need 21 lines. Here...

How to continue reading from stdin after Control-D on OS/X

osx,stdin,eof
I would like to use EOF to terminate reading bulk user input, but continue to be able to accept user CLI input. It seems that Linux allows this behaviour, but OS/X simply shuts down the stdin input steam (as seem from the following test program). Is there any workaround to...

I am trying to read numbers from a file

c++,eof
#include <iostream> #include <fstream> #include <cstdio> #include <stdio.h> using namespace std; int v[101]; int main() { int max=0; int a,i; ifstream f("bac.in"); ofstream g("bac.out"); while(!EOF(f)) { f >> a; while(a>10) if(a%10!=0 && (a/10)%10!=0) v[a%100]++; a/=10; } for(i=10;i<=99;i++) if(v[i]>max) max=v[i]; for(i=10;i<=99;i++) if(v[i]==max) g<<i; } I get the error 14 | error:...

why istream::get sets failbit and eofbit together?

c++,get,eof,istream
I wonder why istream::get sets failbit and eofbit together. The behaviour of std::getline is different: it sets eofbit when it encounters the end of the file, and failbit when you try to read past the end of the file. So you can write: while (std::getline(is, s) { blablabla... // gets...

How to pass string between c++ and c# with null characters inside?

c#,c++,string,eof,const-char
In C++ I have some strings, for example string str = "a\0b\0c"; And I need to pass this string to C# without losing data after "\0",and from c# pass to C++ also without losing data. Can you help me?...

Verify that the expression getchar() != EOF is 0 or 1 [duplicate]

c,eof,getchar
This question already has an answer here: Why doesn't getchar() wait for me to press enter? 9 answers Problem Verify that the expression getchar() != EOF is 0 or 1. Approach I have tried to write a program which will first take an input other than EOF and thus...

Output EOF using %f

c,io,printf,eof,format-specifiers
#include<stdio.h> int main() { printf("%d",EOF); } generates -1 which is totally fine, but #include<stdio.h> int main() { printf("%f",EOF); } produces 0.000 . How can someone explain this when the expected output is -1.000?...

fgetc() doesn't stop in EOF

eof,fgetc
tried to look on forums but could not reslove. I'm trying to read from text. Text is: "To b" But while using fgetc(), EOF is not reached, and at the end I get '\n' and then infinity 'y' samples. Here's my code: Node* getBinTree(FILE *fsrc){ Node* root=NULL; unsigned char tmp=NULL;...

How do i enter an EOF character in this program?

c++,c,eof
i was studying EOF character in c and came across a program : #include <stdio.h> main() { int c= 0; while((c = getchar())!=EOF) putchar(c); } its all good it is giving proper o/p but how do i come out of the loop by entering a EOF character which i entered...

End of File in stdin

c,stdin,eof
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, fgetc() will read all the chars and come to...

counting characters in the input with while loop

c,loops,while-loop,char,eof
I wrote a simple c program to count number of characters #include <stdio.h> main() { long nc; nc = 0; while (getchar() != EOF) ++nc; printf("%ld\n", nc); } This program is not printing me the characters. On testing different cases, I found that I am stuck in an infinite while()...

K&R 1-9 // using getchar in a loop inside a loop

while-loop,eof,getchar,kernighan-and-ritchie
I have this simple program: main() { int c; while ((c = getchar()) != EOF) { if (c == ' ') { while ((c = getchar()) == ' '); putchar(' '); if (c == EOF) break; } putchar(c); } } As I understand it, there are two loops. The condition...