views:

58

answers:

1

Hey guys,

I have my code below that consits of a structure, a main, and a function. The function is supposed to display two parameters that have certain values, both of which point to the same structure.

The problem I dont know how to add the SECOND parameter onto the following code :

#include<stdio.h>

#define first 500
#define sec 500


struct trial{
  int f;
  int r;
  float what[first][sec];
};

int trialtest(trial *test);

main(){
  trial test;
  trialtest(&test);
}

int trialtest(trial *test){
  int z,x,i;
  for(i=0;i<5;i++){
      printf("%f,(*test).what[z][x]);
    }
  return 0;
}

I need to add a new parameter test_2 there (IN THE SAME FUNCTION) using this code :

  for(i=0;i<5;i++){
      printf("%f,(*test_2).what[z][x]);

How does int trialtest(trial *test) changes ? and how does it change in main ?

I know that I should declare test_2 as well, like this :

trial test,test_2;

But what about passing the address in the function ? I do not need to edit it right ?

  trialtest(&test); --- This will remain the same ?

So please, tell me how would I use test_2 as a parameter pointing to the same structure as test, both in the same function..

Thank you !! Please tell me if you need more clarification

+1  A: 

I think that this is your homework, so I'll just write a different function that may give you an idea of what (I think) you need to do. I read that you don't want to change the trail_test parameter list, so I stuck with a similar parameter list.

struct thing {
   /* put some stuff here */
};
typedef struct thing thing; /* because this is C, not C++ */

int how_many_things(thing * thing_list);

int main(void) {
     int i;
     thing * a;
     int count_init = random(); /* let's surprise ourselves and make a random number of these */
     count_init %= 128; /* but not too many or it might not work at all */

     a = malloc(count_init*sizeof(things)+1);
     for (i = 0; i < count_init; i++) {
         thing_init(&(a[i]));
     }
     make_illegal_thing(&(a[count_init]) ); /* like '\0' at the end of a string */

     printf("There are %i things in the list\n", how_many_things(a) );

     return 0;
}

/* This is very similar to strlen */
int how_many_things(thing * a) {
    int count = 0;
    while (is_legal_thing(a) ) {
        a++;
        count++;
    }
    return count;
}
nategoose