Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/01/2015, 14:21
Avatar de vangodp
vangodp
 
Fecha de Ingreso: octubre-2013
Mensajes: 934
Antigüedad: 10 años, 6 meses
Puntos: 38
Respuesta: Estructuras y funciones

use las etiquetas para identar el código. Te ayudara a que mas personas lo analicen.
Vas a Highlight y elijes el lenguaje. Luego pega tu código entre las etiquetas para que se vea bien.
Código C:
Ver original
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. struct materias {
  5.     char nom_materias[25];
  6.     int n[3];
  7.     float prom;
  8.    
  9. };
  10.  
  11. struct estudiante {
  12.     char codigo[8];
  13.     char nombre[25];
  14.     char apellido[25];
  15.     char direccion[25];
  16.     int telefono[12];
  17.     int edad[3];
  18.    
  19.    
  20. };
  21. int ingresar_estudiantes ( estudiante *A, materias *B );
  22. void mostrar_estudiantes ( estudiante *A, materias *B, int n );
  23. int main() {
  24.     estudiante iv;
  25.     materias jv;
  26.     int op, x = 0, z = 0;
  27.     int n = 0, num;
  28.    
  29.     do {
  30.         system ( "cls" );
  31.         printf ( "\tPROGRAMA DE REGISTRO ESTUDIANTIL\n\n" );
  32.         printf ( "Eliga una opcion del menu\n" );
  33.         printf ( "1) Ingrese datos del estudiante: \n" );
  34.         printf ( "2) mostrar datos del estudiante: \n" );
  35.         printf ( "3) Buscar estudiante: \n" );
  36.         printf ( "4) Salir \n" );
  37.         printf ( "Ingrese una opcion: " );
  38.        
  39.         scanf ( "%d", &op );
  40.        
  41.        
  42.         switch ( op ) {
  43.             case 1:
  44.                 z = ingresar_estudiantes ( &iv, &jv );
  45.                
  46.                 break;
  47.                
  48.             case 2:
  49.            
  50.                 mostrar_estudiantes ( &iv, &jv, z );
  51.                
  52.                 break;
  53.                
  54.             case 3:
  55.            
  56.            
  57.                 break;
  58.                
  59.             case 4:
  60.                 printf ( "saliendo...\n" );
  61.                 break;
  62.                
  63.             default:
  64.                 printf ( "*****ERROR EN LA OPCION*****\n\n" );
  65.                
  66.                 getch();
  67.                
  68.         }
  69.     } while ( op != 4 );
  70. }
  71.  
  72.  
  73.  
  74. int ingresar_estudiantes ( estudiante *A, materias *B ) {
  75.     int op, x = 0;
  76.     int n = 0, num;
  77.     system ( "cls" );
  78.    
  79.    
  80.     printf ( "INGRESE EL NUMERO DE ESTUDIANTES A REGISTRAR:" );
  81.     scanf ( "%d", &n );
  82.    
  83.     if ( n < 1 ) {
  84.         printf ( "\nINGRESE AL MENOS 1 ESTUDIANTE" );
  85.         printf ( "\nDESEA INTENTARLO DE NUEVO: S/N" );
  86.         op = getch();
  87.     }
  88.    
  89.    
  90.    
  91.    
  92.    
  93.     A = ( estudiante * ) malloc ( sizeof ( estudiante ) * n );
  94.    
  95.     for ( int i = 0; i < n; i++ ) {
  96.         printf ( "Ingrese codigo del estudiante [%d]: ", i + 1 );
  97.         fflush ( stdin );
  98.         scanf ( " %[^\n]", A [i].codigo );
  99.        
  100.        
  101.         printf ( "Ingrese Nombres del estudiante [%d]: ", i + 1 );
  102.         fflush ( stdin );
  103.         scanf ( " %[^\n]", A [i].nombre );
  104.        
  105.        
  106.         printf ( "Ingrese apellidos del estudiante [%d]: ", i + 1 );
  107.         fflush ( stdin );
  108.         scanf ( " %[^\n]", A [i].apellido );
  109.        
  110.         printf ( "Ingrese la direccion del estudiante [%d]: ", i + 1 );
  111.         scanf ( " %[^\n]", A [i].direccion );
  112.        
  113.         printf ( "Ingrese el telefono del estudiante [%d]: ", i + 1 );
  114.         scanf ( "%d", &A [i].telefono );
  115.        
  116.        
  117.         printf ( "Ingrese la edad del estudiante [%d]: ", i + 1 );
  118.         scanf ( "%d", &A [i].edad );
  119.        
  120.        
  121.         {
  122.             system ( "cls" );
  123.             printf ( "\nINGRESE EL NUMERO DE MATERIAS A ESTUDIAR" );
  124.             scanf ( "%d", &num );
  125.            
  126.            
  127.            
  128.            
  129.             printf ( "\nSOLO SE PUEDE ESTUDIAR DE 1 A 6 MATERIAS POR SEMESTRE" );
  130.            
  131.             system ( "pause" );
  132.            
  133.         } while ( num < 1 || num > 6 );
  134.        
  135.         B = ( materias * ) malloc ( sizeof ( materias ) * num );
  136.        
  137.         for ( int y = 0; y < num; y++ ) {
  138.             printf ( "INGRESE LA MATERIA %d :", y + 1 );
  139.             fflush ( stdin );
  140.             scanf ( "%s", B[i].nom_materias );
  141.         }
  142.     }
  143.    
  144.     getch();
  145.    
  146.     return n;
  147.    
  148. }
  149.  
  150. void mostrar_estudiantes ( estudiante *A, materias *B, int n ) {
  151.     int x;
  152.    
  153.     for ( x = 0; x < n; x++ ) {
  154.         printf ( "EL CODIGO DEL ESTUIDANTE ES: %s", ( A + x )->codigo );
  155.         printf ( "\nEL NOMBRE DEL ESTUIDANTE ES: %s", & ( A + x )->nombre );
  156.         printf ( "\nEL APELLIDO DEL ESTUIDANTE ES: %s", & ( A + x )->apellido );
  157.         printf ( "\nLA DIRECCION DEL ESTUIDANTE ES: %s", & ( A + x )->direccion );
  158.         printf ( "\nEL TELEFONO DEL ESTUIDANTE ES: %d", *A[x].telefono );
  159.         printf ( "\nLA EDAD DEL ESTUIDANTE ES: %d", *A[x].edad );
  160.         system ( "pause" );
  161.     }
  162.    
  163. }