#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
typedef struct {
int matricula;
float salario;
} Funcionario;
int ler_dados( void ) {
int dado;
printf ( "Digite a matrícula:\t " ) ; return dado;
}
float ler_salario( void ) {
float salario;
printf ( "Digite o valor do salário:\t " ) ; return salario;
}
int inserir_funcionario( Funcionario ** funcionarios, int tamanho) {
* funcionarios
= realloc ( * funcionarios
, sizeof ( Funcionario
) * ( tamanho
+ 1 ) ) ; ( * funcionarios) [ tamanho] .matricula = ler_dados( ) ;
( * funcionarios) [ tamanho] .salario = ler_salario( ) ;
return ++ tamanho;
}
int main( void ) {
Funcionario
* funcionarios
= malloc ( sizeof ( Funcionario
) ) ; int tamanho = 0 ;
for ( int i = 0 ; i < 5 ; i++ ) {
printf ( "Sizeof : %lu\n " , sizeof ( Funcionario
) ) ; printf ( "Executou: %d\n " , i
+ 1 ) ; printf ( "Tamanho: %d\n \n " , tamanho
) ; tamanho = inserir_funcionario( & funcionarios, tamanho) ;
printf ( "\n dado: %d\n \n " , funcionarios
[ tamanho
] .
matricula ) ; }
}
//https://pt.stackoverflow.com/q/326686/101
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPGxvY2FsZS5oPgoKdHlwZWRlZiBzdHJ1Y3QgewogICAgaW50IG1hdHJpY3VsYTsKICAgIGZsb2F0IHNhbGFyaW87Cn0gRnVuY2lvbmFyaW87CgppbnQgbGVyX2RhZG9zKHZvaWQpIHsKICAgIGludCBkYWRvOwogICAgcHJpbnRmKCJEaWdpdGUgYSBtYXRyw61jdWxhOlx0Iik7CiAgICBzY2FuZigiICVkIiwgJmRhZG8pOwogICAgcmV0dXJuIGRhZG87IAp9CmZsb2F0IGxlcl9zYWxhcmlvKHZvaWQpIHsKICAgICAgZmxvYXQgc2FsYXJpbzsKICAgICAgcHJpbnRmKCJEaWdpdGUgbyB2YWxvciBkbyBzYWzDoXJpbzpcdCIpOwogICAgICBzY2FuZigiICVm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