hey guys ! so im learning c, got a question:

so say i have a struct of students and inside the struct is name , id , fatherName, motherName.

like this

struct stds {

int id;
char name[21];
char fatherName[21];
char motherName[21];

} std[100];

suppose they are 100 stds and i want to find them by typing id.....

printf ("Search for a student record, type id: ");
scanf ("%i",&searchid);

I want to view their name ,fathers name and mothers name by typping his id, how would i do that?

Thanks brouss !

Well this is how you access an element of std[100] and get its elements.

std[searchid].id
std[searchid].name
std[searchid].fatherName
std[searchid].motherName
commented: (y) +0
Well this is how you access an element of std[100] and get its elements.

std[searchid].id
std[searchid].name
std[searchid].fatherName
std[searchid].motherName

how i didnt think of that! how stupid stupid ....
Thanks! u rock!

oh w8 but if i do that i will be searching for the array number
and not for the custom id number right?

Yes, you will searching for the element contained in the array std. If you need to search id in the array std then you could loop through std and check each id.

size_t i = 0;

for (; i < 100; ++i)
{
    if (std[i].id == some_int)
    {
        //do something here
    }
}

i thought about that, just couldnt quite put it toghether xD
Thanks again.

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.