2022-03-24 12:31 AM
typedef struct{
uint8_t data[10];
uint8_t time[10];
uint8_t description[10];
} FileString;
FileString Datalogger_FileString;
Datalogger_FileString.data[0]=0; //ERROR: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
What do I should do to access the array inside a struct? Thank you
Solved! Go to Solution.
2022-03-24 12:48 AM
Your code snippet compiles fine. May be some stray non-ASCII chars if you copy-pasted the code from elsewhere.
Edit: The above holds, but I automatically assumed that the last two lines appeared later in some function.
You cannot put assignments (statements) at global level,unlike in Python for example.
You could init with
FileString Datalogger_FileString1 = { .data[0]=0 };
But since all globally defined variables are initialized to 0 by the C runtime, there is no effect in doing so.
hth
KnarfB
2022-03-24 12:48 AM
Your code snippet compiles fine. May be some stray non-ASCII chars if you copy-pasted the code from elsewhere.
Edit: The above holds, but I automatically assumed that the last two lines appeared later in some function.
You cannot put assignments (statements) at global level,unlike in Python for example.
You could init with
FileString Datalogger_FileString1 = { .data[0]=0 };
But since all globally defined variables are initialized to 0 by the C runtime, there is no effect in doing so.
hth
KnarfB
2022-03-27 10:58 PM
Thank you. I notice that the syntax depends on where you initialize the variable. As global, you must initialize as you said:
FileString Datalogger_FileString1 = { .data[0]=0 };
If you are inside a function you can init as I do.
Datalogger_FileString.data[0]=0;
Thank you