hi! am supposed to make a program, where information are in a structure and should be able to store up to 100 records.. i was able to make the add and display feature.. but now, i am having a hard time with displaying a particular record given the kind.. well, here's the code..

#include<conio.h>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<dos.h>
#include<stdlib.h>



struct ID
{
char Zone[20];
char ID[10];
};

  
struct TimberRec{
    char Kind[30];
    int Diameter;
    int Weight;
    int Height;
    struct ID TimberID;
};struct TimberRec TimberArray[100];

void add(struct TimberRec TImberArray[]);
void displayall(struct TimberRec TimberArray[]);
void displaykind(struct TimberRec TimberArray[]);
void displayweight(struct TimberRec TimberArray[]);
void bye();

int cnt=0;

void main()
{
    int choice;

    do
    {
    clrscr();
    textcolor(WHITE);


        

gotoxy(1,5);cprintf("***********************************

*********************************************");
        

gotoxy(1,20);cprintf("**********************************

**********************************************");
        gotoxy(20,8);printf("TIMBER RECORDS 

MAIN MENU");
        gotoxy(20,10);cprintf("[1] Add New 

Record");
        gotoxy(20,11);cprintf("[2] Display All 

Records");
        gotoxy(20,12);cprintf("[3] Display Record 

using Timber Kind");
        gotoxy(20,13);cprintf("[4] Display Record 

using Timber Weight");
        gotoxy(20,14);cprintf("[5] Display Record 

using TimberID");
        gotoxy(20,15);cprintf("[6] Exit");
        gotoxy(20,17);cprintf("Please enter your 

choice [1-6]");
        fflush(stdin);
        scanf("%d", &choice);
        switch(choice){
        case 1:
            if(cnt==100)
            {
            printf("Record Full!");
            }
            else{
            add(TimberArray);
            cnt++;}
            break;

        case 2: displayall(TimberArray);
            break;

        case 3: displaykind(TimberArray);
            break;
        }
    }while(choice!=6);
    getch();
    }
//****************end of switch*******************/


void add(struct TimberRec TimberArray[])
{
clrscr();
gotoxy(30,5);printf("ADD RECORD");
gotoxy(20,8);printf("INPUT LOCATION OF TIMBER:");
fflush(stdin);
gets(TimberArray[cnt].TimberID.Zone);
gotoxy(20,10);printf("INPUT ID NUMBER:");
gets(TimberArray[cnt].TimberID.ID);
gotoxy(20,12);printf("ENTER KIND OF TIMBER:");
gets(TimberArray[cnt].Kind);
gotoxy(20,14);printf("ENTER TIMBER DIAMETER:");
fflush(stdin);
scanf("%d",&TimberArray[cnt].Diameter);
gotoxy(20,16);printf("ENTER TIMBER WEIGHT:");
fflush(stdin);
scanf("%d",&TimberArray[cnt].Weight);
gotoxy(20,18);printf("ENTER TIMBER HEIGHT:");
fflush(stdin);
scanf("%d",&TimberArray[cnt].Height);
getch();
}

//=========end of void add=======

void displayall(struct TimberRec TimberArray[])
{
for(int i=0;i<cnt;i++)
{
clrscr();
gotoxy(20,5);printf("THE VALUES ARE:");
gotoxy(20,8);printf("TIMBER LOCATION: %s", 

TimberArray[i].TimberID.Zone);
gotoxy(20,10);printf("ID NUMBER: %s", 

TimberArray[i].TimberID.ID);
gotoxy(20,12);printf("TIMBER TYPE: %s", TimberArray[i].Kind);
gotoxy(20,14);printf("TIMBER DIAMETER: %d", 

TimberArray[i].Diameter);
gotoxy(20,16);printf("TIMBER HEIGHT: %d", 

TimberArray[i].Height);
gotoxy(20,18);printf("TIMBER WEIGHT: %d", 

TimberArray[i].Weight);
}
getch();
}

//----------end of displayall


//====================START OF DISPLAY KIND====//*/

void displaykind(struct 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&&Found==0)
{
    scanf("%c %c %s %d %d %d % 

%*c",&TimberArray[x].TimberID.Zone,&TimberArray[x].TimberID

.ID,TimberArray[x].Kind, &TimberArray[x].Diameter, 

&TimberArray[x].Weight, &TimberArray[x].Height);

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

}
    if(Found)
    {
    gotoxy(8,6);printf("Zone: %c", 

TimberArray[x].TimberID.Zone);

}
}
}

i need it really urgent... so if anyone can take a look at it and help me with the displaykind function, i would greatly appreciate it.. thanks in advance

Target is declared as a string but you treat it as a single char in the call to scanf() and then you treat the single char as a string in strcmp. You similarly type mismatch single char for strings in other scanf() calls, too.

What's the feof thingamabob? You need to read through the elements of TimberArray which has nothing to do with a file that I can tell.

See:
this, this, and this


And nothing is urgent on this board... ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.