Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/01/2015, 10:40
david17_619
 
Fecha de Ingreso: enero-2015
Mensajes: 2
Antigüedad: 9 años, 4 meses
Puntos: 0
Estructuras y funciones

Necesito crear una estructura para estudiantes y funciones para ingresar alumnos y otra funcion para mostrar, el arreglo de la estructura debe ser segun el numero de estudiantes....
Este es mi codigo y tengo problemas para mostrar los datos NECESITO AYUDA URGENTE X FAVOR!!!!!

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
struct materias
{
char nom_materias[25];
int n[3];
float prom;

};

struct estudiante
{
char codigo[8];
char nombre[25];
char apellido[25];
char direccion[25];
int telefono[12];
int edad[3];


};
int ingresar_estudiantes(estudiante *A,materias *B);
void mostrar_estudiantes(estudiante *A,materias *B,int n);
int main()
{
estudiante iv;
materias jv;
int op,x=0,z=0;
int n=0,num;

do{
system("cls");
printf("\tPROGRAMA DE REGISTRO ESTUDIANTIL\n\n");
printf("Eliga una opcion del menu\n");
printf("1) Ingrese datos del estudiante: \n");
printf("2) mostrar datos del estudiante: \n");
printf("3) Buscar estudiante: \n");
printf("4) Salir \n");
printf("Ingrese una opcion: ");

scanf("%d",&op);


switch(op)
{
case 1:
z=ingresar_estudiantes(&iv,&jv);

break;

case 2:

mostrar_estudiantes(&iv,&jv,z);

break;

case 3:


break;

case 4:
printf("saliendo...\n");
break;
default:
printf("*****ERROR EN LA OPCION*****\n\n");

getch();

}
} while (op!=4);
}



int ingresar_estudiantes(estudiante *A,materias *B)
{
int op,x=0;
int n=0,num;
system("cls");


printf("INGRESE EL NUMERO DE ESTUDIANTES A REGISTRAR:");
scanf("%d",&n);
if (n<1)
{
printf("\nINGRESE AL MENOS 1 ESTUDIANTE");
printf("\nDESEA INTENTARLO DE NUEVO: S/N");
op=getch();
}





A=(estudiante*)malloc(sizeof(estudiante)*n);
for(int i=0;i<n;i++)
{
printf("Ingrese codigo del estudiante [%d]: ",i+1);
fflush(stdin);
scanf(" %[^\n]",A [i].codigo);


printf("Ingrese Nombres del estudiante [%d]: ",i+1);
fflush(stdin);
scanf(" %[^\n]",A [i].nombre);


printf("Ingrese apellidos del estudiante [%d]: ",i+1);
fflush(stdin);
scanf(" %[^\n]",A [i].apellido);

printf("Ingrese la direccion del estudiante [%d]: ",i+1);
scanf(" %[^\n]",A [i].direccion);

printf("Ingrese el telefono del estudiante [%d]: ",i+1);
scanf("%d",&A [i].telefono);


printf("Ingrese la edad del estudiante [%d]: ",i+1);
scanf("%d",&A [i].edad);


{
system("cls");
printf("\nINGRESE EL NUMERO DE MATERIAS A ESTUDIAR");
scanf("%d",&num);




printf("\nSOLO SE PUEDE ESTUDIAR DE 1 A 6 MATERIAS POR SEMESTRE");

system("pause");

} while(num<1||num>6);

B=(materias*)malloc(sizeof(materias)*num);
for(int y=0;y<num;y++)
{
printf("INGRESE LA MATERIA %d :",y+1);
fflush(stdin);
scanf("%s",B[i].nom_materias);
}
}
getch();

return n;

}

void mostrar_estudiantes(estudiante *A,materias *B,int n)
{
int x;
for(x=0;x<n;x++)
{
printf("EL CODIGO DEL ESTUIDANTE ES: %s",(A+x)->codigo);
printf("\nEL NOMBRE DEL ESTUIDANTE ES: %s",&(A+x)->nombre);
printf("\nEL APELLIDO DEL ESTUIDANTE ES: %s",&(A+x)->apellido);
printf("\nLA DIRECCION DEL ESTUIDANTE ES: %s",&(A+x)->direccion);
printf("\nEL TELEFONO DEL ESTUIDANTE ES: %d",*A[x].telefono);
printf("\nLA EDAD DEL ESTUIDANTE ES: %d",*A[x].edad);
system("pause");
}

}

Última edición por david17_619; 04/01/2015 a las 11:00 Razón: Nuevo codigo