Re: Pointers and nested structures
- From: mark_bluemel@xxxxxxxxx
- Date: 28 Nov 2006 00:54:34 -0800
Computer Wizard (surely some mistake - if you ask these questions
you're no Wizard) wrote:
Hello,
I am really scrwed up with the following stuff:
struct employee
{
char* employee_name;
};
OK - so employee_name points to some storage. How did you assign the
storage?
struct department
{
char* department_name;
struct employee* emp; //Collection of all employees in a
department
};
Please don't use "//" comments in usenet postings - they wrap and mess
things up.
They are also not supported in the C standards most commonly used.
In your department structure, you have a pointer to an employee
structure - where do you assign the space for the employee structure?
(Alternatively you have a point to the first of an array of employee
structures - where do you assign the space for them?)
In main(), I wrote
struct department* company;
So company is a pointer to a department structure (is that really what
you meant?). Where do you assign the space for the department
structure. (Or again, where do you assign the space for the
array of department structures?)
I want to first enter the name of department and
then names of employees in that department. I tried with pointers but I
must hv messed up somewhere n getting segmentation faults.
"hv" ? "n"? Please type in English. You are clearly capable of doing
so.
Tried using
array representation e.g. company[i].emp[j].employee_name . This also
failed.
If you haven't assigned space, then whether you express your operations
directly as pointer operations or as array operations, they will still
fail.
I used new operator but it didn't help.
There is no "new" operator in C. If you want to ask about C++, go to an
appropriate newsgroup. If you want to dynamically allocate space in C,
look at using the malloc() family of functions.
Please tell me how to deal such thing in pointers.
There's a lot to do here and much of it could be better done by reading
some books or online tutorials.
However if you really want us to help you, post a complete program
showing what you have tried and describe what happened.
Thanks!!!
.
- References:
- Pointers and nested structures
- From: Computer Wizard
- Pointers and nested structures
- Prev by Date: Re: Pointers and nested structures
- Next by Date: Re: removing newline character from the buffer read by fgets
- Previous by thread: Re: Pointers and nested structures
- Next by thread: a scanf() question
- Index(es):
Relevant Pages
|
|