Ver Mensaje Individual
  #4 (permalink)  
Antiguo 18/02/2015, 13:15
Avatar de ElenaJuarez
ElenaJuarez
 
Fecha de Ingreso: febrero-2015
Ubicación: Buenos Aires
Mensajes: 8
Antigüedad: 9 años, 3 meses
Puntos: 0
Respuesta: Vector de punteros

Hola de nuevo, si vangodp entendí,gracias. Estuve buscando en un libro, intente hacer un ejercicio y nada no me sale ordenar, pero creo que algo entendí el concepto. Yo intento explicar para no transcribir todo el ejercicio. Lo que intenté fue esto:
Código C:
Ver original
  1. #include<stdio.h>
  2. #define MAX 3
  3. struct DATOS{
  4.    
  5.     char nombre[30];
  6.     int nota;
  7.    
  8. };
  9.  
  10.  
  11. void ingreso(struct DATOS [], int );
  12. void mostrar(struct DATOS [], int );
  13. //void ordenar(* [], int L);
  14.  
  15. void main(){
  16.    
  17.     struct DATOS vec[MAX], *punt[MAX],*paux;
  18.     int i,k;
  19.    
  20.     ingreso(vec,MAX);
  21.     //inicializacio0n de punteros
  22.    
  23.     for(i=0;i<MAX;i++){
  24.         punt[i]=&vec[i];
  25.     }
  26.    
  27.     //ordenamiento
  28.    
  29.     for(i=0;i<MAX;i++){
  30.         for(k=0;k<MAX-i-1;k++){
  31.             if(punt[k]->nota < punt[k+1]->nota){
  32.                
  33.                 paux=punt[k];
  34.                 punt[k]=punt[k+1];
  35.                 punt[k+1]=paux;
  36.             }
  37.         }
  38.     }
  39.    
  40.     mostrar(vec,MAX);
  41.    
  42.    
  43. }
  44.  
  45.  
  46. void ingreso(struct DATOS v[], int L){
  47.    
  48.     int i;
  49.    
  50.     for(i=0;i<L;i++){
  51.        
  52.         printf("\nIngrese nombre: ");
  53.         gets(v[i].nombre);
  54.         printf("\nIngrese nota: ");
  55.         scanf("%d", &v[i].nota);
  56.         getchar();
  57.     }
  58.    
  59. }
  60.  
  61. void mostrar(struct DATOS v[], int L){
  62.    
  63.     int i;
  64.    
  65.     for(i=0;i<L;i++){
  66.        
  67.         printf("\nNombre: %s",v[i].nombre);
  68.         printf("\nNota: %d",v[i].nota);
  69.    
  70.     }
  71.    
  72. }


Pero no ordena, puede ser por algo mal en el vector de punteros? O sea, ordenar normalmente puedo, pero esto de los punteros no lo asimilo todavía.
Ahh tambien me gustaría poder ordenar con una funcion, pero ni me salió!!!