Store information in an array and display it

1

I have a code about movies that have their types in which I try to store their information in an array.

At the time of collecting the data I must be doing it wrong since when using the function to show the crashea movies.

Sometimes I print nulls when I show the list of movies. I did tests to print the first position of the array, but it does not, since I deduce that this is a problem when collecting the data, I do not really know why that with the scanf does not work for me.

It is the first time on this page so all constructive criticism is grateful. Attachment code:

void listarpeliculascine(struct t_cine cine){
printf("hola mundo\n");
    printf("%s\n",cine.peliculas[0]);
  }

struct t_pelicula pedirDatosDePelicula(){
// No te hace falta poner la palabra "struct". Con poner t_pelicula peli es suficiente. Esta funci�n lo que hace realmente es pedirDatosDePelicula() por lo tanto... deber�a DEVOLVER los datos de la pel�cula.
struct t_pelicula peli;
printf("Introduzca el nombre de la pelicula:\n");
scanf("%s",&peli.nombre );
printf("Introduzca el director de la pelicula:\n");
scanf("%s",&peli.director );
printf("Introuzca los actores de la pelicula:\n");
scanf("%s",&peli.actores);
printf("Pelicula a%cadida con exito!\n",164);
return peli;

 }

int main() {
// TODO: Aqu� deber�as tener una variable de tipo tCine declarada. En este tCine tienes que almacenar TODOS los datos. En vez de declarar una pel�cula declara un cine con algo as�: tCine cine (no hace falta poner struct, el struct lo has declarado ya arriba de todo).
struct t_cine cine1;
struct t_pelicula peli;
int n, opcion;
int aux=0;
do{
    mostrarmenu();
    printf("Introduzca una de las siguientes opciones:\n");
    scanf("%i",&opcion );
    switch (opcion) {
        case 1:
        peli = pedirDatosDePelicula(); //Se asigna asi?
        //printf("%s\n",peli.nombre);
                                    cine1.peliculas[aux]=peli;
                                     aux++;
                                     break;
        case 2: listarpeliculascine(cine1);break;
            // 1. Aqu� tienes que, primero, pedir los datos de la pel�cula y devolverlos rellenados (obviamente aqu� la funci�n a la que llames no debe devolver void, sino un tPelicula. La funci�n a la que denominas "incluirpelicula"
            //    deber�a llamarse algo as� como "pedirDatos()". Este pedirDatos devolver� el tPelicula relleno.
            // 2. Una vez devuelta la pel�cula en la funci�n pedirDatos() deber�s recogerlos en una variable en el main y A�ADIRLOS al struct de tipo tCine que tienes que tener declarado al principio del main.
        case 3:
        break;
        case 4:eliminarpelicula(cine1);break;
        case 5:printf("Esta usted saliendo del programa...\n");break;
        default:
  printf("Tienes que selecionar una opcion correcta.\n" );
    }
}while(opcion!=5);
return 0;
 }
    
asked by Jeylou 15.04.2018 в 21:21
source

1 answer

1

How have you declared the structures? (Notice how you declare them since your comment says that it is not necessary to put struct) .... The variable cinema, apparently should be an arrangement, so if you have not defined it as such in the struct declaration, you should create the variable as an arrangement:

tcine cine1[30];

So the way to access the positions and store movies in cine1, should be:

cine1[0].peliculas = peli;
cine1[aux].peliculas = peli;

This always and when, the cinema structure contains a variable of type t_pelicula, so that the previous assignment is fulfilled. Since ".peliculas" and "peli" have to be of the same type.

    
answered by 17.04.2018 в 21:53