C ++ program error: "[Error] expected primary-expression before 'F1'"

0

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

The error:

  

[Error] expected primary-expression before 'F1'

Could anyone 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);

}
    
asked by anonymous 09.10.2017 / 02:45

1 answer

1

The line where this error is displayed is as follows:

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

That actually has several errors:

  • Missing% with%
  • Type ; is not indicated in the function call, and should only be Fila
  • The first parameter of the function F1 is a ocorre so it is necessary to pass Fila* and not &F1 to match type
  • The second parameter of the function F1 is ocorre and not char and char* qualifies as &X logo must be char* only

To resolve compilation errors, you need 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 it has no compile errors.

    
09.10.2017 / 03:03