#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[ 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
) ; funcionarios
= realloc ( funcionarios
, sizeof ( Funcionario
) * ( tamanho
+ 1 ) ) ; tamanho = inserir_funcionario( funcionarios, tamanho) ;
}
}
//https://pt.stackoverflow.com/q/326686/101
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPGxvY2FsZS5oPgoKdHlwZWRlZiBzdHJ1Y3QgewogICAgaW50IG1hdHJpY3VsYTsKICAgIGZsb2F0IHNhbGFyaW87Cn0gRnVuY2lvbmFyaW87CgppbnQgbGVyX2RhZG9zKHZvaWQpIHsKICAgIGludCBkYWRvOwogICAgcHJpbnRmKCJEaWdpdGUgYSBtYXRyw61jdWxhOlx0Iik7CiAgICBzY2FuZigiICVkIiwgJmRhZG8pOwogICAgcmV0dXJuIGRhZG87IAp9CmZsb2F0IGxlcl9zYWxhcmlvKHZvaWQpIHsKICAgICAgZmxvYXQgc2FsYXJpbzsKICAgICAgcHJpbnRmKCJEaWdpdGUgbyB2YWxvciBkbyBzYWzDoXJpbzpcdCIpOwogICAgICBzY2FuZigiICVmIiwgJnNhbGFyaW8pOwogICAgICByZXR1cm4gc2FsYXJpbzsKfQppbnQga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