Originally Posted by
abhi143
I have already accepted my mistake. Again I am really sorry. I apologize for my mistake. I took that just for example. I wanted to change it in program. But I have realized that I don't have good understanding of structure. That's why I didn't write any further program.. I am still confuse on structure. I thought to start new thread on structure. I stopped and thought. I felt that after spending some time I should do it. because I have presented myself in wrong way. I am reading and I will back soon with code
it is called struc for the very simple reason of the definition of the word , "structure"
the arrangement of and relations between the parts or elements of something complex.
hence a complex means of storing different data types into one 'box" for safe keeping, while still giving the program a means to access same said data types, one at a time or more while keeping them all self contained within the same box at all times. therefore one can now create a more complex "data type". If one was to try and define a car using data types and not putting them all into a box then it gets messy. we have to take a few characteristics of a car then use data types to describe a car. tires, doors, color; just using three.
Code:
int main()
{
int tires = 4;
int doors = 2;
char * color = "white";
// if you wanted two cars then you will run
// into problems with your variable names.
return 0 ;
}
to access that and keep it all together if more than one car can get really confusing to keep track of. using a struc or a complex data type it is easier to keep track of , change its values within it, and even create more than one car, record for a person , but if you have two people now what?
Without having somewhere to keep all of the data separate but still using the same variable names, you will be having to come up with creative names for each time you create a new car so your variables will not cause conflict with each other, then you have to keep track of everything in what it is called,it too can get really lengthy having to type a new name for each one.
Code:
char name1[20], name2[20],name3[20],name4[20], ...
char address1[30],address2[30],address3[30],address4[30],...
if I need a 100 names, and addresses or more even. That is a lot to keep track of that way. let lone all of the writing one will have to do.
just stick it in a structure
Code:
struct list {
char Name[30];
int number;
char address[50];
struct list *next;
};
then after that program is written without a struc and you get a new name and you only have it written for 5000 names and address, then you get name number 5001. your program is useless.
the example left in here demonstrates how to elevate that problem. using a struct. Now using a data type and its same variable name,
It can be used multiple times to keep multiple different names distinctly for each different person along with whatever else you want to keep on them, all using the same data types with their same variable name and not over writing that same variable with a different name each time you access it to put another persons name inside of it.
this way it keeps everything separate but together at the same time by using the same data type and their same variable names keeping multiple different values within it, while with the use of linking it together to keep track of them all so you can find them and work with them. hence the linked list was then invented to deal with that side of it.