Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. void crash(char *str);
  2.  
  3. int _tmain(int argc, _TCHAR* argv[])
  4. {
  5. POLINOM triangle;
  6. NODE_COORD tab[3];
  7. int i;
  8.  
  9. for(i=0; i<3; ++i)
  10. {
  11. tab[i].coord = (double *)malloc(2*sizeof(double));
  12. if(!tab[i].coord)
  13. crash("memory alloc. error");
  14.  
  15. tab[i].coord[0] = (i+1)*i;
  16. tab[i].coord[1] = (i+3)/(i+1);
  17. }
  18.  
  19. if(!POLINOM_Init(&triangle, 3, tab))
  20. crash("POLINOM_Init error");
  21.  
  22. POLINOM_Free(&triangle);
  23.  
  24. for(i=0; i<3; ++i)
  25. {
  26. if(tab[i].coord)
  27. free(tab[i].coord);
  28. tab[i].coord = NULL;
  29. }
  30.  
  31. return 0;
  32. }
  33.  
  34.  
  35. void crash(char *str)
  36. {
  37. printf("%s\n", str);
  38. system("pause");
  39. exit(1);
  40. }
  41. ------------------------------------------------------------------------
  42. bool POLINOM_Init(POLINOM *ob, size_t NoVertexes, NODE_COORD *arr)
  43. {
  44. size_t vert;
  45. ob->NoVertexes = NoVertexes;
  46.  
  47. ob->crd = (NODE_COORD *)malloc(NoVertexes*sizeof(NODE_COORD));
  48. if(!ob->crd)
  49. return false;
  50.  
  51. for(vert=0; vert<NoVertexes; ++vert)
  52. {
  53. ob->crd[vert].coord = (double *)malloc(2*sizeof(double));
  54. if(!ob->crd[vert].coord)
  55. return false;
  56. memcpy((void *)ob->crd[vert].coord, (const void *)arr[vert].coord, _msize(arr[vert].coord));
  57. }
  58.  
  59. return true;
  60. }
  61.  
  62. void POLINOM_Free(POLINOM *ob)
  63. {
  64. size_t vert;
  65. if(ob->crd)
  66. {
  67. for(vert=0; vert<ob->NoVertexes; ++vert)
  68. {
  69. free(ob->crd[vert].coord);
  70. }
  71. free(ob->crd);
  72. }
  73. ob->crd = NULL;
  74. }
  75.  
  76. void POLINOM_Print(POLINOM *ob);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement