Advertisement
jhon345

Untitled

Sep 26th, 2014
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. # include <stdio.h>
  2. # include <stdlib.h>
  3. # include <string.h>
  4. typedef struct ficha {
  5. char nome[50];
  6. int idade;
  7. char sexo;
  8. }Ficha;
  9. int main(){
  10. Ficha dados[3],*candidatos;
  11. int i=0,pessoa=0,j;
  12. for(j=0;j<3;j++){
  13. printf("Digite nome :");
  14. scanf("%s",dados[j].nome);
  15. fflush(stdin);
  16. printf("Digite idade :");
  17. scanf("%d",&dados[j].idade);
  18. fflush(stdin);
  19. printf("Digite o sexo :");
  20. scanf(" %c",&dados[j].sexo);
  21.  
  22. if((dados[j].idade >18)&&(dados[j].sexo=='m')){
  23. pessoa = pessoa+1;
  24. }
  25. }
  26. candidatos=(Ficha*)malloc(sizeof(Ficha)*pessoa);
  27. for(i=0;i<pessoa;i++){
  28. for(j=0;j<3;j++){
  29. if((dados[j].idade>18)&&(dados[j].sexo=='m')){
  30. strcpy(candidatos[i].nome , dados[j].nome);
  31. candidatos[i].idade = dados[j].idade;
  32. candidatos[i].sexo = dados[j].sexo;
  33.  
  34. }
  35. }
  36.  
  37. }
  38. for(i=0;i<pessoa;i++){
  39. printf("%d",candidatos[i].idade);
  40. fflush(stdin);
  41. printf("%s",candidatos[i].nome);
  42. fflush(stdin);
  43. printf("%c",candidatos[i].sexo);
  44. }
  45.  
  46. free(candidatos);
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement