Advertisement
fellpz

Struct

Aug 22nd, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct flsal {
  5.     char *nome;
  6.     int matricula;
  7.     float salario;
  8. };
  9.  
  10. typedef struct flsal Folha;
  11.  
  12. Folha *inserirDados(char *nome, int matricula, float salario);
  13. void exibir(Folha *funcionario);
  14. void imprimir(Folha *funcionario);
  15.  
  16. int main () {
  17.     Folha *bem10, *gabryel, *vitor;
  18.     char nom1[]="Lucas", nom2[]="Gabryel", nom3[]="Vitor";
  19.  
  20.     bem10 = inserirDados("Lucas", 1610039, 1000.00);
  21.     gabryel = inserirDados("Gabryel", 1610024, 900.00);
  22.     vitor = inserirDados("Vitor", 1610069, 7000.00);
  23.  
  24. /*  bem10.nome = "Lucas";
  25.     gabryel.nome= "Gabryel";
  26.     vitor_rubens.nome = "Vitor";
  27.  
  28.     bem10.matricula = 20161610040;
  29.     gabryel.matricula = 201616010024;                     //SUBSTITUINDO O PROCESSO ACIMA
  30.     vitor_rubens.matricula = 20161610069;
  31.  
  32.     bem10.salario = 1000;
  33.     gabryel.salario = 900;
  34.     vitor_rubens.salario = 7000;                     */
  35.  
  36. /*   printf("%s >>", bem10.nome);
  37.     printf("%d >>", bem10.matricula);
  38.     printf("%f \n", bem10.salario);
  39.  
  40.     printf("%s >>", gabryel.nome);
  41.     printf("%d >>", gabryel.matricula);
  42.     printf("%f \n", gabryel.salario);
  43.  
  44.     printf("%s >>", vitor.nome);
  45.     printf("%d >>", vitor.matricula);
  46.     printf("%f \n", vitor.salario);                  */
  47.  
  48.     return 0;
  49. }
  50.  
  51. Folha *inserirDados(char *nome, int matricula, float salario){
  52.     Folha *funcionario;
  53.     funcionario = (Folha *) malloc(sizeof(Folha));
  54.  
  55.     funcionario -> nome = *nome;  // = (*funcionario).nome = *nome;
  56.     funcionario -> matricula = matricula; // "
  57.     funcionario -> salario = salario; // "
  58.  
  59.     return funcionario;
  60. }
  61.  
  62. void exibir(Folha *funcionario) {
  63.     printf("%s >> %d >> R$%.2f \n", funcionario -> nome, funcionario -> matricula, funcionario -> salario );
  64. }
  65.  
  66. void imprimir(Folha *funcionario) {
  67.     FILE *file;
  68.     file = fopen("dadosFuncionarios.txt", "a"); //r - read / a - alter
  69.     fprintf(file, "%s >> %d >> R$%.2f \n", funcionario -> nome, funcionario -> matricula, funcionario -> salario);
  70.     fclose(file);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement