Welcome, Guest. Please login or register.

Author Topic: GAH!!!! Help w/passing array of structure to a function...  (Read 1626 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline TheMagicMTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2857
    • Show only replies by TheMagicM
    • http://www.BartonekDragRacing.com
GAH!!!! Help w/passing array of structure to a function...
« on: January 12, 2005, 05:02:02 AM »
example...


struct tele2_struct{
   fname[30];
   lname[30];
   whatever[70];
}db[750];


int search_array(struct tele2_struct, char parm_searchvar);

then in main() I have something similiar like...

found_record = search_array(db, searchvar);

I basically want to pass a array which contains various info and what they are searching for which is stored in searchvar.. but I get a error @ found_record which says...

 conversion from `tele2_struct*' to non-scalar type `
   tele2_struct' requested


and I'm lookin at examples here and there..but I cannot find one similiar to mine... stumped by something simple which I cannot figure out.
PowerMac G5 dual 2.0ghz/128meg Radeon/500gb HD/2GB RAM, MorphOS 3.9 registered, user #1900
Powerbook G4 5,6 1.67ghz/2gb RAM, Radeon 9700/250gb hd, MorphOS 3.9 registered #3143
 

Offline Lando

  • Hero Member
  • *****
  • Join Date: Jun 2002
  • Posts: 1390
    • Show only replies by Lando
    • https://bartechtv.com
Re: GAH!!!! Help w/passing array of structure to a function...
« Reply #1 on: January 12, 2005, 05:08:08 AM »
Try found_record = search_array(db[0], searchvar);

But, you should really pass a pointer to the structure rather than trying to pass the structure itself.
 

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: GAH!!!! Help w/passing array of structure to a function...
« Reply #2 on: January 12, 2005, 07:06:03 AM »
Expanding on Lando's suggestion. . . .

It sounds like you want to do something like this:
Code: [Select]

struct tele2_struct {
    char fname[30];    /* gotta specify a type   */
    char lname[30];    /* using char for example */
    char whatever[70];
} db[750];

int search_array(struct tele2_struct* ptele2, unsigned int psize, char parm_searchvar);

int main()
{
    char searchvar = 0;

    int res = search_array(db, sizeof(db), searchvar);
}

int search_array(struct tele2_struct* ptele2, unsigned int psize, char parm_searchvar)
{
    int res = 0;
    unsigned int i;
    struct tele2_struct* p = ptele2;

    for (i = 0; i < psize; i++) {
        /* do something with p->fname[], p->lname[], etc. */
        /* place the result in `res' */
        p++;
    }

    return res;
}

You can play with passing pointers, pointers to pointers, and references. Your final decision on what to use should be based partially on your requirements and partially on your coding style. . . .

Trev
 

Offline TheMagicMTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2857
    • Show only replies by TheMagicM
    • http://www.BartonekDragRacing.com
Re: GAH!!!! Help w/passing array of structure to a function...
« Reply #3 on: January 12, 2005, 12:29:30 PM »
LOL...yep...that'd be it..  thanks!
PowerMac G5 dual 2.0ghz/128meg Radeon/500gb HD/2GB RAM, MorphOS 3.9 registered, user #1900
Powerbook G4 5,6 1.67ghz/2gb RAM, Radeon 9700/250gb hd, MorphOS 3.9 registered #3143