error

H

HW

Hi

I have the following code, (it reads from th paralel port.) but I get
the following error
unexpected EOF while looking for matching `"'
here is the code
#include <stdio.h>
#include <sys/io.h>
#include <sys/time.h>

/* Adam's uber-hacky electricity usage monitor */

/* Base address of parallel port */
#define BASE 0x378
/* Flashes per kilowatt hour */
#define PER_KWH 800.0
/* Number of readings to average */
#define AVG 3

int status = BASE + 1;
int laston = 0;

void wait_change() {
int on;
unsigned char v;

do {
v = inb(status);
on = !!(v & 0x80);
usleep(1000);
} while (on == laston);
laston = on;
}

int main(int argc, char **argv) {
int i;
long long lasttime = 0;
double oldvals[AVG];

if (argc < 2) {
fprintf(stderr, "usage: readmeter outputfile tempfile\n");
return 20;
}

if (ioperm(BASE, 3, 1) < 0) {
fprintf(stderr, "ioperm failed\n");
return 20;
}

for (i = 0; i < AVG; i++) oldvals = 0.0;

wait_change();

while (1) {
struct timeval tv;
long long this, diff;
double kw;
int w;
FILE *f;

wait_change();
wait_change();

gettimeofday(&tv, NULL);
this = tv.tv_usec + (1000000 * tv.tv_sec);
diff = this - lasttime;
lasttime = this;

if (diff < 250000 || diff > 10000000) continue;

kw = (3600000000.0 / diff) / PER_KWH;
for (i = 1; i < AVG; i++) oldvals[i - 1] = oldvals;
oldvals[AVG - 1] = kw;
kw = 0;
for (i = 0; i < AVG; i++) kw += oldvals;
kw /= AVG;
w = kw * 1000;

f = fopen(argv[2], "w");
if (f == NULL) {
fprintf(stderr, "couldn't open %s\n", argv[2]);
return 20;
}
fprintf(f, "%d\n", w);
fclose(f);
if (rename(argv[2], argv[1]) < 0) {
fprintf(stderr, "couldn't rename file\n",);
return 20;
}
}

return 0;
}

this is the error

hw@epia:~$ ./energie
../energie: line 81: unexpected EOF while looking for matching `"'
../energie: line 88: syntax error: unexpected end of file
hw@epia:~$

the system is debian sarge.

Is ther anybody who can see the mischmatch????

Thanks in advance

HW
 
H

HW

T.M. Sommers schreef:
There is an extraneous comma here.
Thanks for looking,

I just changed that, and the error is still the same. :-(

hw@epia:~$ ./energie
../energie: line 81: unexpected EOF while looking for matching `"'
../energie: line 88: syntax error: unexpected end of file
hw@epia:~$


any sugestions?

HW
 
C

Christopher Benson-Manica

HW said:
I have the following code, (it reads from th paralel port.) but I get
the following error

Your program is more or less not topical for this newsgroup -
comp.unix.programmer is the place for such things - but syntax errors
are topical, so...
if (rename(argv[2], argv[1]) < 0) {
fprintf(stderr, "couldn't rename file\n",);
^
return 20;
}

That's your problem. Also, turn up your compiler's warning level; the
source file you provided neglected to include several Unix-specific
headers (such as unistd.h) that provide prototypes for several
functions; note that the details of such headers are, again,
appropriate on comp.unix.programmer.
hw@epia:~$ ./energie

That's a strange way to compile a program...
./energie: line 81: unexpected EOF while looking for matching `"'

....and, given the actual problem, that is a spectacularly unhelpful
error message, assuming you posted your cut-and-pasted code. gcc was
more useful in this case.
 
R

Richard Heathfield

HW said:
T.M. Sommers schreef:
Thanks for looking,

I just changed that, and the error is still the same. :-(

Check that you recompiled it properly. I got a syntax error from gcc when
compiling your program. Removing the extra comma allowed the compilation to
complete.
hw@epia:~$ ./energie
./energie: line 81: unexpected EOF while looking for matching `"'
./energie: line 88: syntax error: unexpected end of file
hw@epia:~$

This suggests that you are running the program, rather than compiling it.
Assuming ./energie is your executable file, I suggest you delete it! Then
recompile.
 
K

Kenneth Brody

HW said:
T.M. Sommers schreef:
Thanks for looking,

I just changed that, and the error is still the same. :-(

hw@epia:~$ ./energie
./energie: line 81: unexpected EOF while looking for matching `"'
./energie: line 88: syntax error: unexpected end of file
hw@epia:~$

any sugestions?

Assuming that the source you posted is exactly the code you are
attempting to compile (ie: you pasted the actual code into the
message, rather than typed it in), there is nothing wrong with
your code, as far as I (or my compiler) can see. It compiles
just fine here, once the extraneous comma was removed.

Perhaps something has corrupted one of the system header files?

What if you keep the same header includes at the top, and get rid
of all of the actual code? Does it still complain? What error(s)
do you get then?

BTW, what is "./energie" that you are using to compile?

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
H

HW

This suggests that you are running the program, rather than compiling it.
Assuming ./energie is your executable file, I suggest you delete it! Then
recompile.
Indeed, I was forgotten that c programs need to be compiled rather
interpeted.. I just compiled it an nog ik goed a lot better.

thanks anyway...


HW
 
K

Keith Thompson

HW said:
Hi

I have the following code, (it reads from th paralel port.) but I get
the following error
unexpected EOF while looking for matching `"'
here is the code [snip]
this is the error

hw@epia:~$ ./energie
./energie: line 81: unexpected EOF while looking for matching `"'
./energie: line 88: syntax error: unexpected end of file
hw@epia:~$

<OT>
Those error messages are from the Bourne shell. You're trying to
execute ./energie, and the system is interpreting it as a shell script.
</OT>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top