Re: XForms: problem with fl_get_input

Steve Lamont (spl@szechuan.ucsd.edu)
Sun, 12 Oct 97 12:13:36 PDT

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> ... However I can't even seem to get the data I enter to
> print to the screen or anything. Here is what i have for testing of
> input fields:

> const char *model_num;
> model_num = fl_get_input(model_box);
> printf("%s", model_num);
>
> Am I doing this incorrectly? ...

Looks fine to me. Are you certain `model_box' is of type FL_INPUT?
As someone else suggested, you may want to add a newline ('\n')
character to cause the buffer to get flushed, although if printf() is
writing to the terminal, it should get flushed immediately, even
without a newline. If you are redirecting stdout to a file, then the
buffer will only get flushed when it gets full, of course, unless
fflush() is called.

> ... Also when I try to do:
>
> p_dat.model = fl_get_input(model_box);
>
> Where p_dat is my structure and model is of type char I get an incompatible
> types in assignment error.

How is the `model' member of the struct declared? Is it of the form

struct {
...
char model[MOD_SIZE];
...
} p_dat;

perchance? This will produce this sort of error message from the
compiler.

strcpy( p_dat.model, ( char *) fl_get_input(model_box) );

should produce the expected results

The form you use is more appropriate to assign to a pointer:

struct {
...
char *model;
...
} p_dat;

Also, bear in mind that fl_get_input() returns a pointer to an XForms
internal buffer, the contents of which are subject to arbitrary
change, so you should really do something like

p_dat.model = strdup( ( char *) fl_get_input(model_box) );

to copy the contents of the buffer to your own area, which you should
manage in appropriate the appropriate manner to prevent memory leaks.

spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/