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...
need help! regarding array of structures
Collapse
X
-
Originally posted by zaaczehi! 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... -
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
-
Hi,
Are u using %s to get the value of the variable kind that is
TimberArray[x].Kind
Thanks
RaghuramComment
-
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);
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);
Thanks
RaghuramComment
Comment