Jump to content

[duvida]Exercicio de exame


mundo

Recommended Posts

Bom dia, estou aqui a resolver um teste e nao estou a conseguir fazer um exercicio, envolvendo uma struct.

tenho que fazer uma função int maisFreq(Pauta p, int n) que calcula a nota mais frequente entre os n primeiros alunos da lista p.

O codigo que tenho é o seguinte, com bastantes asneiras, mas nao estou a conseguir resolver, se alguem me puder ajudar agradecia:


#include <stdio.h>
#include <stdlib.h>

#define MAX 300

typedef struct linha{
   int numero;
   char nome[100];
   int nota;
}Pauta[MAX];

int contaElem(Pauta p[MAX], int n){
   int x; //contador
   int i,j;//indices para percorrer o array
   int flag; //determina se foi encontrado

   for(i = 0, j = i+1; i < (n-1); i++, j++){
       if(p->nota[i] == p->nota[j]){
           if(flag == 0){
               x++;
               flag = 1;
           }
       }
       else{
           flag = 0;
       }
   }
   return x;
}

int maisFreq(Pauta p[MAX], int n){
   int t, flag;
   int *moda; //sera o que retornará o valor da nota mais frequente
   int i, j, k;

   t = contaElem(p,n);

   moda = (int *) malloc (t * sizeof(Pauta));

   k = flag = 0;

   for(i = 0, j = i+1; i < (n-1); i++, j++){
       if(p->nota[i] == p->nota[j]){
           if(flag == 0){
               moda[k++] = p->nota[j];
               flag = 1;
           }
       }
       else{
           flag = 0;
       }
   }
   return moda;


}
Link to comment
Share on other sites

In function 'contaElem':

ex1.c:25: error: request for member 'nota' in something not a structure or union

ex1.c:25: error: request for member 'nota' in something not a structure or union

ex1.c: In function 'maisFreq':

ex1.c:50: error: request for member 'nota' in something not a structure or union

ex1.c:50: error: request for member 'nota' in something not a structure or union

ex1.c:52: error: request for member 'nota' in something not a structure or union

ex1.c:60: warning: return makes integer from pointer without a cast

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.