need help! regarding array of structures

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zaacze
    New Member
    • Mar 2007
    • 11

    need help! regarding array of structures

    hi! am really having trouble with array of structures in c.. i'm quite familiar with structures and arrays and yet am having trouble with a program that would enable to search for a specific record. can anybody please do give me a sample of a code that shows searching of records in an array of structures...
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by zaacze
    hi! am really having trouble with array of structures in c.. i'm quite familiar with structures and arrays and yet am having trouble with a program that would enable to search for a specific record. can anybody please do give me a sample of a code that shows searching of records in an array of structures...
    Here are the Posting Guidelines, what part are you having trouble with?

    Comment

    • zaacze
      New Member
      • Mar 2007
      • 11

      #3
      thanks for the reply.. i was actually able to make the add and display options for the array of structure.. but on the search option, after being able to input a name that am searching for, it simply goes back to the main menu.. here's wt i did..

      void displaykind(str uct TimberRec TimberArray[])
      {
      clrscr();
      int Found=0;
      char Target[30];
      int x;

      if((TimberArray[x].Kind)==NULL)
      printf("Record Empty!");
      else
      {
      printf("Enter kind of timber to display");
      fflush(stdin);
      scanf("%c", Target);
      while(!feof&&Fo und==0)
      {
      scanf("%c %c%[^/]%*c %d %d %d %*c",&TimberArr ay[x].TimberID.Zone, &TimberArray[x].TimberID.ID,Ti mberArray[x].Kind, &TimberArray[x].Diameter, TimberArray[x].Weight, TimberArray[x].Height);

      if(strcmp(Targe t, TimberArray[x].Kind)==0)
      Found = 1;

      }
      if(Found)
      {
      gotoxy(8,6);pri ntf("Zone: %c", TimberArray[x].TimberID.Zone) ;

      }
      }
      }

      i just tried to test it with the zone part, but then nothing happens.. did i do something wrong?

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        Hi,
        Are u using %s to get the value of the variable kind that is
        TimberArray[x].Kind

        Thanks
        Raghuram

        Comment

        • zaacze
          New Member
          • Mar 2007
          • 11

          #5
          hi! am i supposed to use %s first? on which part should i put that? am so confused right now...

          Comment

          • gpraghuram
            Recognized Expert Top Contributor
            • Mar 2007
            • 1275

            #6
            HI,
            Change the following line
            Code:
            scanf("%c %c%[^/]%*c %d %d %d %*c",&TimberArray[x].TimberID.Zone,&TimberArray[x].TimberID.ID,TimberArray[x].Kind, &TimberArray[x].Diameter, TimberArray[x].Weight, TimberArray[x].Height);
            to

            Code:
            scanf("%c %c %s %d %d %d ",&TimberArray[x].TimberID.Zone,&TimberArray[x].TimberID.ID,TimberArray[x].Kind, &TimberArray[x].Diameter, TimberArray[x].Weight, TimberArray[x].Height);
            I have removed the specifier %*c.

            Thanks
            Raghuram

            Comment

            • zaacze
              New Member
              • Mar 2007
              • 11

              #7
              hi!!!! it worked!!!! thanks a lot.....

              Comment

              Working...