Advertisement
Guest User

nazismo.c

a guest
Aug 23rd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define limit 50
  5.  
  6. typedef struct data{
  7. int day, month, year;
  8. }Data;
  9.  
  10. typedef struct candidate{
  11. int number;
  12. char name[limit];
  13. float grade; //%4.2f
  14. Data* birth;
  15. }Cand;
  16.  
  17. Cand** allocCand(void){
  18. Cand **array;
  19. int i;
  20. array = (Cand**)malloc(sizeof(Cand*)*limit);
  21. for(i = 0; i < limit; i++){
  22. array[i] = NULL;
  23. }
  24. return array;
  25. }
  26.  
  27. Data* fillData(int d, int m, int y){
  28. Data *da;
  29. da = (Data*)malloc(sizeof(Data));
  30. da->day = d;
  31. da->month = m;
  32. da->year = y;
  33. return da;
  34. }
  35.  
  36. Cand* fillCand(char* name, float g, int dia, int mes, int ano){
  37. Cand *c;
  38. c = (Cand*)malloc(sizeof(Cand));
  39. strcpy(c->name,name);
  40. c->grade = g;
  41. c->birth = fillData(dia,mes,ano);
  42. c->number = rand() % 100000;
  43. return c;
  44. }
  45.  
  46. void printCands(Cand **array){
  47. int i;
  48. for(i=0; array[i] != NULL; i++){
  49. printf("Nome do desgraçado: %s\n Numero de inscricao: %d\n Nota do filho da puta: %4.2f\n Data de Nascimento do Filho da Puta %d/%d/%d\n",array[i]->name,array[i]->number, array[i]->grade, array[i]->birth->day, array[i]->birth->month, array[i]->birth->year);
  50. }
  51. }
  52.  
  53. void freeArray(Cand **array){
  54. free(array);
  55. }
  56.  
  57. int main (void){
  58. Cand **v;
  59. v = allocCand();
  60. v[0] = fillCand("Rogério da Silva", 300.0, 4, 10, 2005);
  61. v[1] = fillCand("He Man do Nordeste", 953.4, 25, 12, 0000);
  62. v[2] = fillCand("Thiagao Abu Yassef", 999.98, 11, 9, 2001);
  63. printCands(v);
  64. freeArray(v);
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement