[SOLVED] Getting error: expected expression before ‘{’ token in C while trying to verify struct


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

#define LEN_ID 3
#define LEN_P 30
#define LEN_CIDADE 50
#define AT 40

typedef struct aeroporto
    char id[LEN_ID + 1];
    char pais[LEN_P + 1];
    char cidade[LEN_CIDADE + 1];
} Aeroporto;

int findavailablespot(Aeroporto l[AT])
    int i = found = 0;
    for (;i<AT;i++) {
        if (l[i] = {"aaa","bbb","ccc"}) //Error in this line
        if (found)
            return i;
            return -1;

So i am creating the structure aeroporto then a vector made up of aeroportos and i want to check if {"aaa","bbb","ccc"} shows up inside the vector.

Sorry for the formatting, new at this


You have to use strcmp() to compare strings. There’s no shortcut for doing this with all the members of a structure, you have to test each one individually and combine with &&.

You also forgot to set found before breaking out of the loop.

int i = 0, found = 0;

for (;i<AT;i++) {
    if (strcmp(l[i].id, "aaa") == 0 && strcmp(l[i].pais, "bbb") == 0 && strcmp(l[i].cidade, "ccc")) {
        found = 1;

Answered By – Barmar

Answer Checked By – Gilberto Lyons (BugsFixing Admin)

Leave a Reply

Your email address will not be published.