Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms in C 1

Status
Not open for further replies.

DanJC

Programmer
Dec 6, 2001
19
0
0
SE
I am attempting to create a form in C using the following concept.

I create a field struct:
Code:
struct field
{
  int index;
  void *point_to_data;
  char *caption;
  int hor_pos, ver_pos;
} myform[15];

I also create a record struct to store data;
Code:
struct myrec
{
  char *item1;
  char *item2;
  struct myrec *next;
} *rec1;
Can I point the void item 'point_to_data' to item1, item2 etc..? to transfer data from screen to an input segment?

If anyone can tell me how to point 'point_to_data' to the data item I would be a very happy bunny.

Dan.

'All good things might seem good at first but at the end of the day they are just things...'
 
Hey Dan,

Well, generic pointers can be used to work with any data type but proper precaution needs to be taken. I hope the following code snippet would help.
Code:
	void *vp;
	char *s="This is a string!";
	int len;

len=strlen(s)-1;

vp = (char *)s;

for(;len>=0;len--)
	printf("%c",*((char *)vp+len));
This code prints the string message in Reverse (!gnirts a...) Let me know if it was helpful!

have fun coding... ;-)

Roy.
user.gif
 
Is this what you meant?

Code:
struct field
{
  int index;
  struct myrec *point_to_data;
  char *caption;
  int hor_pos, ver_pos;
} myform[15];

struct myrec
{
  char *item1;
  char *item2;
  struct myrec *next;
} *rec1;

struct field *MyField;

MyField->point_to_data.item1
Rob
"Programming is like art...It makes me feel like chopping my ear off."

- Currently down
 
Not quite, I want point_to_data to point to one of the data members of the rec1, not the whole record.

The idea is to have the form showing one record at a time.

This means that each field in the form should be one part of struct myrec.

If only my assignment would allow me to use C++!!!

"Flying by the seat of your pants is fun, but it's much safer by aircraft..."

DanJC
 
Well useing RoyOboy's meathod...

struct myrec *MyRecord;
struct field *MyField;

MyRecord.item1 = (char *)MyField[index].point_to_data;

Does that work for ya? Sorry if this is sloppy, i'm at work so it's quick responses ;-)



Rob
"Programming is like art...It makes me feel like chopping my ear off."

- Currently down
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top