Problem due to queuing

Asked

Viewed 87 times

1

I’m trying to create a queue with structs, but it’s not working the assignment section on lines 17/18, I can’t find the error. The logic I’m using is correct?

error: request for member 'nome' in 'FilaAluno', which is of pointer type 'aluno' (maybe you meant to use '->' ?)

FilaAluno[fimfila].nome = FilaAluno.nome;

I’m using Atom with Myngw.

#include <iostream>
using namespace std;
#define max_fila 2
 struct aluno {
  char nome [100];
  int cod;
  int turma;
} ;

bool enfileirar(aluno FilaAluno[], int &i, int &fimfila){
  if (fimfila == max_fila){
    std::cout << "fila cheia" << '\n';
    return false;
  }
  else{
    FilaAluno[fimfila].nome = FilaAluno[i].nome; //problema
    FilaAluno[fimfila].cod = FilaAluno[i].cod; //problema
    FilaAluno[fimfila].turma = FilaAluno[i].turma;
    fimfila++;
  }
  return true;

}
int main(){
  aluno FilaAluno [max_fila]; //fila
  int inifila = 0;
  int fimfila = 0;
  for (int i = 0; i < max_fila; i++) {
    /* code */

    std::cout << "Codigo:" << '\n';
    std::cin >> FilaAluno[i].cod;
    std::cout << "Nome:" << '\n';
    std::cin >> FilaAluno[i].nome;
    std::cout << "Turma:" << '\n';
    std::cin >> FilaAluno[i].turma;

    if(enfileirar (FilaAluno, i, fimfila)){
      std::cout << "Item adicionado com sucesso!" << '\n';
  }
 }
}
  • What do you mean, "it’s not working"? Also, mark with a comment the lines with problem, to avoid that people have to count the lines of code.

  • @pabloalmeida, I just corrected it. It’s not working because it’s giving an attribution error, says it’s invalid. I also don’t know if my logic is correct, because the material of the college is not very good.

  • Thank you, Tiago, but it would be good if you put the exact text of the error.

  • @pabloalmeida, I put the message presented.

1 answer

0

The error message you placed does not match the text: there is no command

FilaAluno[fimfila].nome = FilaAluno.nome;

on the lines of code you showed...

But there is an error in this line

FilaAluno[fimfila].nome = FilaAluno[i].nome; //problema

which should be

memcpy(FilaAluno[fimfila].nome, FilaAluno[i].nome, 100);

but for this to work you need to insert at the beginning of the program this line:

#include <cstring>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.