Re: help with window widgets



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

ybisou wrote:
>  I tried to follow your idea and this is what I did :
> 
>> main()
>> {
>> 	// I made ALL widgets necessary for program
>> 	
>> 	// enter while loop to read all values from stdin
> unsigned int val;
> char buf[5];
> 	read(STDIN_FILENO, &val, sizeof(int));   //1st voltage not used
> 	read(STDIN_FILENO, &val, sizeof(int));   //2nd voltage not used

Perhaps one of the big sticking points is that you are unfamiliar with
C?  Read the man page for read(2) to see why what you're doing here is
likely not what you are trying to do (for what it's worth, I think you
may have had it closer to correct in your original post).  Then, figure
out why you are courting signal 11 by overrunning buf.  Then figure out
easier and less error-prone ways to do all of this.  There are so many
problems with this code that fixing the GTK+ parts of it is not going to
help much.

To get started, I might try writing a simplified version of this program
which just reads from stdin and writes to stdout (i.e., writes buf to
stdout, not val).  When and only when you get the values you expect
should you add in the graphical stuff.  At that point, you may get more
help from folks here.

In other words, work on this program first (errors retained, and note
that I have no idea what your function `ita' is supposed to do, so I
guessed):

#include <unistd.h>
#include <stdio.h>
#include <string.h>

#define ita(x) ((x) + '0')

int main(int argc, char *argv[])
{
    unsigned int val;
    char buf[5];

    while (read(STDIN_FILENO, &val, sizeof(int)))
    {
        buf[0] = ita(val/100);
        buf[1] = ita(val - ((val/100)*100)/10);
        buf[2] = '.';
        buf[3] = ita(val - ((val/100)*10));
        strcat(buf, " V");

        /*
         * Print out the string that you are trying to build
         * here to see if it looks right.
         */
        printf("Read: `%s'\n", buf);
    }

    return 0;
}

Hint: You may want to have a look at the C library functions scanf(3),
printf(3) and all of their friends.

Chris.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFWinCkey5QmfOctcRAnzHAJ0UUfVEJsQgPLKNjiBRvja/LtxRDACglbVg
5jSlXmTsqx4SKjQVCYc+paI=
=3z/q
-----END PGP SIGNATURE-----



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]