Re: [Dev-C++] Question about structs...
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Abhijit S. <mu...@gm...> - 2002-10-23 11:46:58
|
> struct database[100]
No, just
struct database
> {
> int id_number;
> char employee_name[25];
> int age;
> float salary;
> };
>
> To populate it, or to access the individual records within the array, I
> would use the standard for() loops, correct? Same with the emplyee_name[]
> array?
and when you're declaring the variable,
database employees[100];
employee[0].age = 666;
Or, you could use vectors, like Marc said. That would translate to
vector<database> employees;
That would be valid only in C++, not in C. I assume you're working with C.
You could use dynamic memory allocation for variable sized arrays. The
functions that you would use are malloc(), realloc(), free().
Also, you ask about using a variable to index employee_name. I hope you're
not getting confused about NULL-terminated character arrays (strings).
char name[20];
is a character array. You can use it to store arrays of characters, and if
this array is ended by a NULL-character ('\0'), it becomes a string. So in
the above example, to print the name of the first employee, you would say
printf("%s\n", employee[0].employee_name);
*NOT*
printf("%s\n", employee[0].employee_name[0]);
I hope I helped and didn't just confuse you further.
___________________________________________________________
Abhijit Shylanath
E-mail: mu...@gm... || ibr...@bi...
Web-site: http://mudeth.tripod.com/
|