typedef struct SENSOR
{
float tmin=15.0;
float tmax=25.0;
};
SENSOR s1;main.c: At top level:
main.c:30: warning: no semicolon at end of struct or union
main.c:30: error: syntax error before '=' token
main.c:32: error: syntax error before '}' token
main.c:34: error: syntax error before 's1'
main.c:34: warning: type defaults to 'int' in declaration of 's1'
main.c:34: warning: data definition has no type or storage class
struct s
{
int x;
} t;
typedef struct SENSOR
{
float tmin=15.0;
float tmax=25.0;
};
SENSOR s1;typedef struct// __attribute__((__packed__))
{
float tmin;
float tmax;
} SENSOR;
SENSOR s1;packed
The packed attribute specifies that a structure member should have the smallest possible alignment unless you specify a larger value with the aligned attribute.
Here is a structure in which the member x is packed, so that it immediately follows a, with no padding for alignment:
struct foo
{
char a;
int x[2] __attribute__ ((packed));
}; Note: The device architecture requires that words be aligned on even byte boundaries, so care must be taken when using the packed attribute to avoid run-time addressing errors.
{/quote]
//Inicializa estructuras de SENSOR
void InicializaSENSOR(SENSOR *s)
{
s->tmin=INI_TMIN;
s->tmax=INI_TMAX;
}:mrgreen:
Eso me gusta Gera. Lo voy a poner en práctica.
Te quito tu estrella y te la reemplazo por una más grande :D
Gracias.
wiii gracias!! :D jaja. Me alegra q te haya servido
Código: [Seleccionar]typedef struct SENSOR
{
float tmin=15.0;
float tmax=25.0;
};
SENSOR s1;
typedef struct
{
float tmin;
float tmax;
} SENSOR;
SENSOR s1={15.0, 25.0};sprintf(str, "%f", (double)s1.tmin); //c30 se enoja si no lo paso como doubleDe ultima podes separar la parte entera y decimal, y despues las imprimis.Código: C
float tmin = 12.345; int entero = (int)tmin; int decimal = (int)((tmin - entero) * 1000); //depende de la presicion
Es una solucion media fea, pero por ahi sirve. Si todavia te sigue ocupando mucho el printf, podes convertir los enteros en strings con itoa() y los concatenas.
saludos!!