statement and code:
Make a program that stores movies produced by several directors
and:
- Create and read a vector of 5 directors, each containing name (maximum 20 letters), number of films
and movies. The movie member is a vector, which must be created after reading the number of movies. Each
film is composed of name, year and duration.
- Look for a director by name, showing all the movies he has already produced. Repeat the process
until you enter an empty string.
%pre%
My question is: am I allocating the array correctly?
It does not work when I try to put more than 2 movies in the same director!
Thank you.
______ azszpr336404 ___
My question is: am I allocating the array correctly?
Not at all. The allocation was done based on the %code% size, allocating a %code% vector but the %code% type is %code% :
%pre%
In other words, it has allocated a vector of directors and saved it in a double char pointer, so the types and sizes do not play. If your array is an array of %code% to save strings declared as %code% then the correct allocation would be:
%pre%
Note that I omitted cast because it is not required. I should also add that calling the %code% field would be much brighter than it represents, instead of %code% .
But I can not help saying that this does not answer the statement. The statement clearly states that:
Each movie consists of name, year and duration
Then %code% should be a structure:
%pre%
And now this would be the structure used within %code% :
%pre%
The allocation would now be:
%pre%
Now it's not enough to adjust the remaining code for this new movie structure.
___