【发布时间】:2022-11-02 02:21:43
【问题描述】:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int busqueda_indexada(int a[], int n, int x) {
int elementos[3]; int indice[3];
int g; int i;
int set=0; int ind=0;
for (i=0; i<n-1; i+=3) {
elementos[ind].nombre=a[i]);
elementos[ind].indice = i;
i+=3;
ind++;
}
if (x<elementos[0].boleto) {
return -1;
} else {
for (i=1; i<g-1; i++)
if (x<elementos[i].elem) {
int ini = elementos[i-1].indice;
int fin = elementos[i].indice;
set = 1;
break;
}
}
if (set==0) {
int ini = elementos[G-1].indice;
int fin = n-1;
}
}
struct elementos {
int indice;
char nombre[100];
int boleto;
} elementos a[3];
int main(int argc, char *argv[]) {
struct elementos a[3] = {"marco", 1, "sin asignar", 2, "pedro", 3};
printf("%s y %d", a[2].nombre, a[2].boleto);
busqueda_indexada(a, n, x)
return 0;
}
我不知道索引搜索如何读取我的结构。我尝试了一切并且总是显示
[错误] 在非结构或联合的情况下请求成员“”
每次我试图调用一个结构。也许我定义了错误的结构或者我以错误的方式调用它?
【问题讨论】:
-
请您修复缩进 - 这将使代码更易于阅读
-
@mkrieger1 - 感谢修复缩进
标签: c