Problem with pointers and printf

0

The following error is marked in the part that shows the file found (in case it is found)

'apnom' has not been declared 

I do not understand if you tell me because I'm making some mistake in the function

struct alumnos * buscaleg (struct alumnos [ ], int *, int);

Thank you very much

struct fecha
{ 
   int dia;
   int mes; 
   int anio;
};

struct alumnos
{
   int legajo;
   char apnom [35];
   char direc [40];
   struct fecha fe [2];  /* fecha nacimiento y fecha ingreso institución */
   int edad;
 };

 void carga_alu (struct alumnos [ ], int *); 
 struct alumnos * ordenaap (struct alumnos [ ], int);
 struct alumnos * buscaleg (struct alumnos [ ], int *, int);
 int main() 
 {

 struct alumnos alum[100];
 struct alumnos *punt;
 int cantalum=0, leging;
 struct alumnos *puntbusc;

 carga_alu(alum,&cantalum); 

 punt=ordenaap (alum,cantalum);
 printf("Arreglo ordenado: \n");
 for (int i=0; i<=cantalum-1;i++)
 { printf("El nombre del alumno es: %s \n", punt[i].apnom);
   printf("El legajo del alumno es: %d \n", punt[i].legajo);
   printf("La direccion del alumno es: %s \n", punt[i].direc);
   printf("La fecha de nacimiento del alumno es %d/%d/%d   \n",punt[i].fe[0].dia,punt[i].fe[0].dia,punt[i].fe[0].dia);
   printf("La fecha de ingreso del alumno es %d/%d/%d \n",punt[i].fe[1].dia,punt[i].fe[1].dia,punt[i].fe[1].dia);
   printf ("La edad del alumno es: %d \n", punt[i].edad); }

  printf("Ingrese el legajo del alumno a buscar");
  scanf ("%d", &leging);
  puntbusc=buscaleg(punt,&leging,cantalum);
  if (puntbusc==00000)
  { printf("El legajo no existe"); }
  else {printf("El nombre del alumno es: %s \n", puntbusc.apnom);
     printf("El legajo del alumno es: %d \n", puntbusc.legajo);
     printf("La direccion del alumno es: %s \n", puntbusc.direc);
     printf("La fecha de nacimiento del alumno es %d/%d/%d   \n",puntbusc.fe[0].dia,puntbusc.fe[0].dia,puntbusc.fe[0].dia);
     printf("La fecha de ingreso del alumno es %d/%d/%d \n",puntbusc.fe[1].dia,puntbusc.fe[1].dia,puntbusc.fe[1].dia);
     printf ("La edad del alumno es: %d \n", puntbusc.edad);}  




   system("PAUSE");
   return 0; 
   }


   void carga_alu (struct alumnos a[ ], int *c)
   {
   char rta='s';
   int i=0;
   while (rta=='s')
   { printf("Ingrese el nombre y apellido del alumno \n");
     gets(a[i].apnom);
     printf("Ingrese el legajo del alumno \n");
     scanf("%d",&a[i].legajo);
     while(getchar()!='\n');
     printf("Ingrese la direccion del alumno \n");
     gets(a[i].direc);
     printf("Ingrese la fecha de nacimiento del alumno: DIA \n");
     scanf("%d", &a[i].fe[0].dia); /*En fe[] pongo 0 porq la primer posicion   la uso para la fecha de nac*/
     while(getchar()!='\n');
     printf("Ingrese la fecha de nacimiento del alumno: MES \n");
     scanf("%d", &a[i].fe[0].mes);
     while(getchar()!='\n');
     printf("Ingrese la fecha de nacimiento del alumno: ANIO \n");
     scanf("%d", &a[i].fe[0].anio);
     while(getchar()!='\n');
     printf("Ingrese la fecha de ingreso a la institucion del alumno: DIA  \n");
     scanf("%d", &a[i].fe[1].dia);/*En fe[1] pongo 1 porque la segunda  posicion la uso para la fecha de ingreso*/
     while(getchar()!='\n');
     printf("Ingrese la fecha de ingreso a la institucion del alumno: MES  \n");
     scanf("%d", &a[i].fe[1].mes);
     while(getchar()!='\n');
     printf("Ingrese la fecha de ingreso a la institucion del alumno: ANIO \n");
     scanf("%d", &a[i].fe[1].anio);
     while(getchar()!='\n');
     printf("Ingrese la edad del aluno: \n");
     scanf ("%d", &a[i].edad);
     while(getchar()!='\n');
     *c=*c+1;
     i=i+1;
     printf("Desea cargar otro alumno? S o N \n");
     scanf("%c",&rta);
     while(getchar()!='\n');} }


     struct alumnos* ordenaap (struct alumnos a[], int ca) 
     {

     for(int i=0; i<=ca-1;i++)
     {  for (int m=0; m<=ca-2;m++)
       { if(a[m].apnom>a[m+1].apnom)
           {struct alumnos aux=a[m];
            a[m]=a[m+1];
            a[m+1]=aux;} } }

    return a; }


   struct alumnos * buscaleg (struct alumnos alumo[], int *li, int canta)
   {
   int bajo=0,alto=canta-1,centro;
   while (bajo<=alto)
   { centro=(bajo+alto)/2;
     if (*li=alumo[centro].legajo)
      { return &alumo[centro]; }
      else if (*li<alumo[centro].legajo)
             {alto=centro-1;}
      else {bajo=centro+1;} }

  alumo[canta].legajo=00000;
  return &alumo[centro]; }
    
asked by Maca Igoillo 31.01.2017 в 18:07
source

1 answer

2

You have several problems in your code, but I'm going to start with the failures that I understand you're complaining about the compiler.

You define a puntbusc variable, pointer to the student class.

struct alumnos *puntbusc;

However, in the printf obvious that the variable is a pointer and you use a . instead of -> :

 printf("El nombre del alumno es: %s \n", puntbusc.apnom);

You have to change it for:

 printf("El nombre del alumno es: %s \n", puntbusc->apnom);

And so with all the other printf statements:

 printf("El legajo del alumno es: %d \n", puntbusc->legajo);
 printf("La direccion del alumno es: %s \n", puntbusc->direc);
 printf("La fecha de nacimiento del alumno es %d/%d/%d   \n",puntbusc->fe[0].dia,puntbusc->fe[0].dia,puntbusc->fe[0].dia);
 printf("La fecha de ingreso del alumno es %d/%d/%d \n",puntbusc->fe[1].dia,puntbusc->fe[1].dia,puntbusc->fe[1].dia);
 printf ("La edad del alumno es: %d \n", puntbusc->edad);

In this way, the compiler will stop complaining about apnom.

EDIT1 :

On the other hand, you have this if in the search function:

if (*li=alumo[centro].legajo)

I understand that what you want is to make a comparison ( == ) not an assignment ( = ) right?

    
answered by 31.01.2017 / 18:29
source