Create a new structure/class, create an Array of the structure (empty).
I only know how to do this in JAVA and I tried this for testing but I always get this error:
error: 'Teste' was not declared in this scope In function 'int ler(Teste*, int)':
In function 'int main()':
Bad error line: -3
I've tried this:
typedef struct _Teste
{
int position;
int frequency;
}Teste;
int ler(Teste* k, int cont)
{
return cont;
}
static int cont=1;
int main()
{
Teste novo[12];
cont=ler(novo, cont);
return 0;
}
C/C++ requires function prototypes if a call to a function precedes its definition. That is the compiler will issue an error, because the function you try to call is unknown (not yet defined).
Wiring/Arduino supports automatic prototype generation. These prototypes are added to the top of the source file (before passing it to the C/C++ compiler). It is not very smart however, so in this case the type referenced in your function header has not been declared yet. That's why you get this error (check the line number).
Bad error line: -3
If you add a prototype (an empty function declaration) manually, you should be ok.
It's not mandatory to use the loop() and setup() functions, but you still have to declare them...
C/C++ requires function prototypes if a call to a function precedes its definition. That is the compiler will issue an error, because the function you try to call is unknown (not yet defined).
Wiring/Arduino supports automatic prototype generation. These prototypes are added to the top of the source file (before passing it to the C/C++ compiler). It is not very smart however, so in this case the type referenced in your function header has not been declared yet. That's why you get this error (check the line number).
Quote:
Bad error line: -3
If you add a prototype (an empty function declaration) manually, you should be ok.
You're saying I should do this before doing everything else?
Your original file is absolutely correct C (and C++) code and can be compiled (by itself) by any reasonable compiler.
However, if you want to compile it from inside the Arduino environment, it's probably easiest to do it the "Arduino way."
Create a library and put the struct definition there.
If you don't already have a subdirectory named libraries in your sketchbook drectory create one. Then, in that directory create a new subdirectory, say teststruct Put your struct definition in a file named teststruct.h in the teststruct directory. Delete the struct definition from your main .pde file.
Then in the Arduino environment, import that library. It will put #include <teststruct.h> at the top of your sketch (the .pde file). Then the C++ file that actually gets compiled will have things defined in correct sequence to make the compiler happy.