C++ program error: "[Error] expected Primary-Expression before 'F1'"

Asked

Viewed 2,659 times

0

Hello, good evening everyone! I have a problem in my occurrence function of a number in the vector.

The mistake:

[Error] expected Primary-Expression before 'F1'

Could someone help me solve this problem? Thanks in advance!

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <locale>
#define TAM 4

struct Fila {
    char M[TAM];
    int Com, Fim, Total;
};

//INICIANDO A FILA
void Qinit(Fila *F){
   F->Com = F->Fim = F->Total = 0;
}
//COLOCANDO ELEMENTOS NA FILA
void Enqueue(Fila *F,char X){
    if (F->Total < TAM){ //existência de espaço na fila
        F->M[F->Fim] = X;
        F->Fim++;
        if (F->Fim == TAM){
            F->Fim = 0;
        } 
        F->Total++;
    }
}
//FUNÇÃO DE REMOÇÃO DE ELEMENTOS
char Dequeue(Fila *F){
    if (F->Total > 0) {
        char X = F->M[F->Com];
        F->Total--;
        F->Com++;
        if (F->Com == TAM){
            F->Com = 0;
        }
        return X;
    }
}
//MOSTRAR ELEMENTOS DA FILA
void mostra(Fila *F) {
     int i; 
     printf("[");
     int cont = F->Com;
     for (i = 0; i < F->Total; i++) {
        printf("%c", F->M[cont]);
        //VÍRGULAS
        if (i != F->Total-1) {
            printf(",");
        }   

        cont++;
        if (cont == TAM){
            cont = 0;
        }
     }
      printf("]");
}
//OCORRÊNCIA DE UM NÚMERO
int ocorre(Fila *F, char elem){
    int cont, igual;
    igual = 0;
    for (cont=1; cont == F->Total-1; cont++) {
        if (elem == F->M[cont]) {
            igual++;
        }
    return igual;
    } 
}


//PROGRAMA PRINCIPAL
main (void) {
   Fila F1;
   int op;
   char elemLido, X;
   Qinit(&F1);
   do {
    system("cls");
    printf("-----------FILAS------------");
    printf("\n1. Insere");
    printf("\n2. Remove");
    printf("\n3. Ocorrências");
    printf("\n4. Inicio Inserir");
    printf("\n5. SAIR");
    printf("\n----------------------------\n");
    mostra(&F1);
    printf("\n----------------------------");
    printf("\nSua opção:");
    scanf("%i",&op);
    switch(op){
        case 1: fflush(stdin);
                printf("\nElemento:");
                scanf("%c",&elemLido);
                Enqueue(&F1,elemLido);
                break;

        case 2: printf("\nElemento removido: %c\n", Dequeue(&F1));
                system("Pause");
                break;

        case 3: 
                printf("\n Elemento: ");
                scanf("%c",&X);
                printf("\nNúmero de Ocorrências: %i", ocorre(Fila F1, &X))

                break;
       }

   } while (op != 10);

}

1 answer

1


The line where this error is shown is as follows:

printf("\nNúmero de Ocorrências: %i", ocorre(Fila F1, &X))

That actually has several mistakes:

  • The ;
  • The guy Fila is not indicated in function call, and should only be F1
  • The first function parameter ocorre is a Fila* soon it is necessary to pass &F1 and not F1 to match the type
  • The second function parameter ocorre is a char and not a char* and &X qualifies as char* soon must be X only

To solve build errors you will have to change this line to:

printf("\nNúmero de Ocorrências: %i", ocorre(&F1, X));

This does not mean that the program works correctly, but at least there are no compilation errors.

Browser other questions tagged

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