B
Bill Reid
#define MAX_VALUES 64
typedef struct {
unsigned value_1;
double value_2;
double value_3;
double value_4;
} VALUES;
typedef struct {
unsigned num_values;
unsigned tot_value_1;
double tot_value_2;
double tot_value_3;
double tot_value_4;
VALUES values[MAX_VALUES];
} VALUES_STRUCT;
VALUES_STRUCT values_struct=
{3,0,0.0,0.0,0.0,{{1,1.0,1.0,1.0},{1,1.0,1.0,1.0},{1,1.0,1.0,1.0}}};
double add_double_numbers
(void *number,unsigned num_numbers,unsigned inc_size) {
void *void_ptr=NULL;
char *inc_ptr=number;
double *double_ptr=NULL;
unsigned number_num=0;
double total=0.0;
while(number_num<num_numbers) {
void_ptr=inc_ptr;
double_ptr=void_ptr;
total+=*double_ptr;
inc_ptr+=inc_size;
number_num++;
}
return total;
}
void add_value_4(void) {
values_struct.tot_value_4=add_double_numbers
(&values_struct.values[0].value_4,values_struct.num_values,
sizeof(VALUES));
printf("\nThe total is %f",values_struct.tot_value_4);
}
int main(void) {
add_value_4();
return 0;
}
typedef struct {
unsigned value_1;
double value_2;
double value_3;
double value_4;
} VALUES;
typedef struct {
unsigned num_values;
unsigned tot_value_1;
double tot_value_2;
double tot_value_3;
double tot_value_4;
VALUES values[MAX_VALUES];
} VALUES_STRUCT;
VALUES_STRUCT values_struct=
{3,0,0.0,0.0,0.0,{{1,1.0,1.0,1.0},{1,1.0,1.0,1.0},{1,1.0,1.0,1.0}}};
double add_double_numbers
(void *number,unsigned num_numbers,unsigned inc_size) {
void *void_ptr=NULL;
char *inc_ptr=number;
double *double_ptr=NULL;
unsigned number_num=0;
double total=0.0;
while(number_num<num_numbers) {
void_ptr=inc_ptr;
double_ptr=void_ptr;
total+=*double_ptr;
inc_ptr+=inc_size;
number_num++;
}
return total;
}
void add_value_4(void) {
values_struct.tot_value_4=add_double_numbers
(&values_struct.values[0].value_4,values_struct.num_values,
sizeof(VALUES));
printf("\nThe total is %f",values_struct.tot_value_4);
}
int main(void) {
add_value_4();
return 0;
}