Im making a library for a raspberry pi program and im running into trouble of a struct variable having an initial value.
myLib.h
typedef struct {
int startingNumber = 0; // this throw an error in C
} myStruct
void increment(myStruct * a){
if(IsNotInitialised(a->startingNumber)) // i dont know ho to checked
printf("starting number is not initialised");
else
a->startingNumber++
}
It is important that the number must be set by the user of library and incase the user forgets to set the value in the main, i would like for the library to throw an error. I have read that if the value of a property of a struct is not set it will default to 0, but thats seems to be not true. what makes it even worse is everytime i run the program the value seems to be randomly set.
so when the user programs inside the main
main.c
#include <myLib.h>
int main(){
myStruct count;
increment(&count); // this must print the error since count.a is not set
}