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 part 2

Status
Not open for further replies.

DanJC

Programmer
Dec 6, 2001
19
0
0
SE
Ok peeps,

C++ makes it a lot easier to create forms/fields than C does so here is some code that may help C programmers:

Code:
//define field structure
struct field
{
  int h_pos, v_pos, width;
  char caption[35];
  char *value;
} form1[10];

//display form
void disp_form( struct field form[], int field_count)
{
  int index;
  for(index = 0; index < field_count; index ++)
  {
     gotoxy(form[index].h_pos, form[index].v_pos);
     printf(&quot;%s&quot;,form[index].caption);
  }
}

//to enter form data in the appropriate &quot;field location&quot;
void get_form_data(struct field form[], int field_count)
{
  int index;
  for(index = 0; index < field_count; index++)
  {
    gotoxy(form[index].h_pos + strlen(form[index].caption) + 2, form[index].v_pos);
    scanf(&quot;%s&quot;, form[index].value);
  }
}

There is a snag to using these functions - you have to create a lengthy procedure to initialise the form fields' data but as this data would be fixed you only do it once in the program and the optimisation would produce quicker programs.

You would use the following procedures:
void form1_init(); //set data for form fields;
void disp_form(form1, 10);//display the form so that all the fields are already on screen
void /*or some data type*/ get_form_data(form1,10);

This takes a lot of work out of allocating data to structures by using repeated gotoxy();printf();scanf(); sequences and allows you to preset the form on screen before data entry.

If/When I get the file module sorted I will post that item as well ...

Hope this helps.

DanJC

bloke 1 &quot;It doesn't work, I've tried it... &quot;
bloke 2 &quot;IT DOES WORK, I'VE DONE IT!!&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top