Oppure

Loading
02/09/11 9:40
drewnik99
Questo è il codice:

[CODE]
struct libri
{
int code;
char title[MAX_TITLE_LEN];
char des[MAX_DES_LEN];
struct libri *next;
};

struct libri *start = 0;

struct libri ***search(const char title[])
{
struct libri **books = (struct libri**) malloc(sizeof(struct libri*));
if(!books)
{
puts("Ricerca interrotta";);
}
books[0] = start;
struct libri ***point;
struct libri *a = (struct libri*)malloc(sizeof(struct libri));
if(!a)
{
puts("Ricerca interrotta";);
}
int s = 1;
for(a = start; a; a = a->next)
{
if(strstr(a->title, title))
{
books = (struct libri **) realloc(books, sizeof(struct comp*) * (s + 1));
if(!books)
{
puts("Ricerca non completata";);
goto ret;
}
point = &books;
(*point)[s] = a;
s++;
}
}
(*point)[0]->code = s - 1;
ret:
return point;
}

[/CODE]

Ho risolto i problemi precedenti, ma ne restano due:
- L'elemento 0 del vettore books è uguale all'elemento 1(notato durante l'esecuzione del programma)
- Se avvio la ricerca in un database vuoto l'istruzione "(*point)[0]->code = s - 1;", restituisce errore.
Ultima modifica effettuata da drewnik99 02/09/11 18:08
aaa
02/09/11 10:02
Il Totem
Usa strstr:
cplusplus.com/reference/clibrary/cstring/strstr/

P.S.: che senso ha confrontare a, che è un puntatore a struct, con strlen, che è un banale intero? Dov'è la definizione di title? Dove viene inizializzato? A cosa serve il terzo for, dato che poi num non viene nemmeno nominato?
aaa