Buongiorno a tutti,
Sto tentando di sviluppare un dispenser automatico di cocktail. La macchina dovrebbe leggere le ricette da alcuni file txt salvati su una scheda SD e poi salvarli in una lista concatenata. Il problema è che quando arrivo a creare la più semplice delle liste, ovvero quella dove salvare i nomi dei vari ingredienti, ho problemi nel malloc.
Aggiungo il codice della libreria creata per maggiore chiarezza:
#include <SPI.h>
#include <SD.h>
#define NOMEFILEINGREDIENTE "ingredienti.txt"
File myFile;
struct ingredienti{
String nome;
struct ingredienti *pun;
};
struct cocktail{
char id;
String nome;
struct ricetta *ric; //puntatore al primo ingrediente della ricetta corrispondente
struct cocktail *pun;
};
struct ricetta{
char id_ingr; //l'id dell'ingrediente
char qt; //quantità espressa tra rapporto percentuale su scala 0-255;
struct ricetta *pun;//puntatore all'ingrediente successivo
};
struct ingrediente* recuperaIngredienti(){
struct ingrediente *p, *punt;
myFile = SD.open(NOMEFILEINGREDIENTE);
p = (struct ingrediente *)malloc(sizeOf(struct ingrediente));
String nome_i = myFile.readStringUntil('\n');
p->nome = nome_i;
punt = p;
while (myFile.available()) {
nome_i = myFile.readStringUntil('\n');
punt->pun = (struct ingrediente *)malloc(sizeOf(struct ingrediente));
punt = punt->pun;
punt->nome= nome_i;
}
punt->pun = NULL;
return p;
}
Il messaggio di errore che viene fuori è :
C:\Users\win7\AppData\Local\Temp\build90b403c598cdbac199c4210a5bd1f21b.tmp\sketch\database.h: In function 'ingrediente* recuperaIngredienti()':
database.h:32: error: expected primary-expression before 'struct'
p = (struct ingrediente *)malloc(sizeOf(struct ingrediente));
^
database.h:32: error: 'sizeOf' was not declared in this scope
p = (struct ingrediente *)malloc(sizeOf(struct ingrediente));
^
database.h:34: error: invalid use of incomplete type 'struct ingrediente'
p->nome = nome_i;
^
database.h:29: error: forward declaration of 'struct ingrediente'
struct ingrediente* recuperaIngredienti(){
^
database.h:38: error: invalid use of incomplete type 'struct ingrediente'
punt->pun = (struct ingrediente *)malloc(sizeOf(struct ingrediente));
^
database.h:29: error: forward declaration of 'struct ingrediente'
struct ingrediente* recuperaIngredienti(){
^
database.h:38: error: expected primary-expression before 'struct'
punt->pun = (struct ingrediente *)malloc(sizeOf(struct ingrediente));
^
database.h:39: error: invalid use of incomplete type 'struct ingrediente'
punt = punt->pun;
^
database.h:29: error: forward declaration of 'struct ingrediente'
struct ingrediente* recuperaIngredienti(){
^
database.h:40: error: invalid use of incomplete type 'struct ingrediente'
punt->nome= nome_i;
^
database.h:29: error: forward declaration of 'struct ingrediente'
struct ingrediente* recuperaIngredienti(){
^
database.h:42: error: invalid use of incomplete type 'struct ingrediente'
punt->pun = NULL;
^
database.h:29: error: forward declaration of 'struct ingrediente'
struct ingrediente* recuperaIngredienti(){
^
Uso la libreria LiquidCrystal alla versione 1.0.4 nella cartella: C:\Program Files\Arduino\libraries\LiquidCrystal
Uso la libreria SPI alla versione 1.0 nella cartella: C:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI
Uso la libreria SD alla versione 1.0.6 nella cartella: C:\Program Files\Arduino\libraries\SD
exit status 1
expected primary-expression before 'struct'
Qualcuno sa come poter risolvere questo problema?
Grazie in anticipo