[英]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.