简体   繁体   English

出现错误:在尝试验证结构时,C 中“{”标记之前的预期表达式

[英]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
            break;
        if (found)
            return i;
        else
            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.所以我正在创建结构aeroporto ,然后创建一个由 aeroportos 组成的向量,我想检查 {"aaa","bbb","ccc"} 是否出现在向量中。 Help?帮助?

Sorry for the formatting, new at this抱歉格式化,这是新的

You have to use strcmp() to compare strings.您必须使用strcmp()来比较字符串。 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.您还忘记了在跳出循环之前设置found

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;
        break;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C Global Struct:“错误:&#39;{&#39;令牌之前的预期表达式” - C Global Struct: “error: expected expression before '{' token” 在CI中,编译时收到“错误:&#39;)&#39;标记之前的预期表达式” - In C I am getting an “error: expected expression before ')' token” on compile 指向C中的结构-错误:“ *”标记之前的预期“)” - Pointing to struct in C - error: expected ')' before '*' token 结构错误之前的 C 预期表达式 - C expected expression before struct error 处理错误-C中struct之前的预期表达式 - Dealing with error - expected expression before struct in C 得到“'='标记之前的预期表达式”错误 - Getting “expected expression before '=' token” error 编译时出错:&#39;)&#39;标记之前的预期表达式 - Error while compiling: expected expression before ')' token C 中“)”标记之前的错误预期表达式 - Error expected expression before “)” token in C 如何使用结构 || 在 C 中创建一个 NULL(s) 的 2D char* 数组错误:“{”标记之前的预期表达式 - How to make a 2D char* array with NULL(s) in C with a struct || error: expected expression before '{' token &#39;错误:&#39;{&#39;令牌&#39;之前的预期表达式-矩阵作为struct的成员 - 'error: expected expression before '{' token' - matrix as member of struct
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM