Ahoj,
mám následující problém: Mám strukturu, kterou naplním ve funkci foo(), zde jsou hodnoty správné, když se pak vrátím do mainu, tak hodnoty ze struktury zmizí. Nevíte jak na to? Už nějak nevím...
typedef struct {
uint8_t a;
uint8_t b;
uint8_t c;
uint8_t d;
} struktura;
struktura *foo(struktura *str)
{
uint8_t i;
FILE * pFile;
uint8_t mystring [52];
pFile = fopen ("a.txt" , "r");
if (pFile == NULL) perror ("Error opening file");
else
{
fgets (mystring , 52 , pFile);
fclose (pFile);
}
struktura = (struktura *)(mystring);
return str;
}
int main()
{
struktura *str,h;
str = &h;
str = foo(str);
printf("0x%x \n\r", str->a);
printf("0x%x \n\r", str->b);
printf("0x%x \n\r", str->c);
printf("0x%x \n\r", str->d);
return 0;
}
TIP: Přetáhni ikonu na hlavní panel pro připnutí webu



Nahlásit jako SPAM
IP: 94.113.242.–
God of flame
Zjistit počet nových příspěvků
































