can someone look at this? sorry if its o-t

Gregory Nowak greg at romuald.net.eu.org
Fri May 12 15:43:37 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I don't see any reference to fdata in your code, unless it is defined
somewhere in the header files you include, something I haven't checked
into.

I've tried compiling your code anyway, and found the following:

First, the line that says

dfile=fopen("darg", "w");

has the compiler telling me that dfile is undefined. I'm guessing that
you wanted to write:

FILE *dfile=fopen("darg", "w");

in which case, you should have declared dfile at the top of your
function, following good c/c++ programming practices. Also, when using
fopen, it's a really good idea to check that your pointer is actually
assigned to a open file after you open it.

The next error gcc returns is 4 lines later, saying that dfile isn't a
const char*:

printf(dfile, usr);

I have no clue what you're trying to do here. If you meant to use
dfile as a pointer to an open file, I don't see why you'd want to
print it out to stdout.

I didn't try to fix this farther. Also, I'm wondering why you're
including c++ header files, as if you're fixing to write c++ code, but
then write your code entirely in c? If you're going to do that, then
you might as well include fstream, and use ifstream and ofstream for
file i/o, which in my humble opinion is a heck simpler then using
fopen.

Greg


On Fri, May 12, 2006 at 11:47:17AM -0600, Tyler Littlefield wrote:
> Hay list,
> I know this is off-topic, but it says fdata is out of scope, can someone look at it and tell me what is going on?
> Thanks,
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <unistd.h>
> #include <syslog.h>
> #include <cstdlib>
> #include <iostream>
> struct data{
> int alt;
> char *data;
> char *usern;
> };
> using namespace std;
> int main()
> {
> openlog("Dataplus client", LOG_PID, 0);
>  switch ( fork() ) {
> case -1:
> syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), "There was an error starting the dataplus client.");
> return 1;
> case 0:
> break;
> return 0;
> }
> if ( setsid() < 0 )
> {
> syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), "There was an error starting the dataplus client.");
> return 2;
> }
> syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_NOTICE), "Dataplus client ready.");
> data usr;
> usr.alt=322;
> usr.data="linux";
> usr.usern="tyler/root";
> dfile=fopen("darg", "w");
> int i;
> for (i = 0; i++; i < 12)
> {
> printf(dfile, usr);
> fflush(dfile);
> }
> fclose(dfile);
> return 0;
> }
> _______________________________________________
> Speakup mailing list
> Speakup at braille.uwo.ca
> http://speech.braille.uwo.ca/mailman/listinfo/speakup

- -- 
web site: http://www.romuald.net.eu.org
gpg public key: http://www.romuald.net.eu.org/pubkey.asc
skype: gregn1
(authorization required, add me to your contacts list first)

- --
Free domains: http://www.eu.org/ or mail dns-manager at EU.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQFEZOVp7s9z/XlyUyARAh9CAJ9gOc46dlTB6Vouc1d/VfHpp0PQBwCfZhTa
0uvKvuFwOazS2T6NGgqZ964=
=zlEo
-----END PGP SIGNATURE-----




More information about the Speakup mailing list