0

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 !

Edited by centenond

2
Contributors
5
Replies
29
Views
3 Years
Discussion Span
Last Post by centenond
Featured Replies
  • 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 Read More

  • 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 … Read More

1

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
Comments
(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!

0

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

1

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
    }
}
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.