#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;
}
I don't know how the indexed search can read my structure. I tried everything and always shows
[Error] request for member '' in something not a structure or union
every time I tried to call a structure. Maybe I defined bad my struct or I call it in the wrong way?
CodePudding user response:
With elementos[ind].nombre
You try to access a field on elementos[ind]
, but that itself is a int. .something
in only allowed, if elementos[ind]
would eithet be a struct or an union.
CodePudding user response:
You use elementos
for two different things:
- In
busqueda_indexada()
for a local array ofint
; - Outside any function for a structure.
The error (among a lot more) is given the first time for elementos[ind].nombre
. This is the ind
th element of the local array, an int
, which is clearly no structure.
Please raise the warning level of your compiler to the maximum and correct your code until all errors and warnings are gone.
Use descriptive names for structures and variables.