Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void crash(char *str);
- int _tmain(int argc, _TCHAR* argv[])
- {
- POLINOM triangle;
- NODE_COORD tab[3];
- int i;
- for(i=0; i<3; ++i)
- {
- tab[i].coord = (double *)malloc(2*sizeof(double));
- if(!tab[i].coord)
- crash("memory alloc. error");
- tab[i].coord[0] = (i+1)*i;
- tab[i].coord[1] = (i+3)/(i+1);
- }
- if(!POLINOM_Init(&triangle, 3, tab))
- crash("POLINOM_Init error");
- POLINOM_Free(&triangle);
- for(i=0; i<3; ++i)
- {
- if(tab[i].coord)
- free(tab[i].coord);
- tab[i].coord = NULL;
- }
- return 0;
- }
- void crash(char *str)
- {
- printf("%s\n", str);
- system("pause");
- exit(1);
- }
- ------------------------------------------------------------------------
- bool POLINOM_Init(POLINOM *ob, size_t NoVertexes, NODE_COORD *arr)
- {
- size_t vert;
- ob->NoVertexes = NoVertexes;
- ob->crd = (NODE_COORD *)malloc(NoVertexes*sizeof(NODE_COORD));
- if(!ob->crd)
- return false;
- for(vert=0; vert<NoVertexes; ++vert)
- {
- ob->crd[vert].coord = (double *)malloc(2*sizeof(double));
- if(!ob->crd[vert].coord)
- return false;
- memcpy((void *)ob->crd[vert].coord, (const void *)arr[vert].coord, _msize(arr[vert].coord));
- }
- return true;
- }
- void POLINOM_Free(POLINOM *ob)
- {
- size_t vert;
- if(ob->crd)
- {
- for(vert=0; vert<ob->NoVertexes; ++vert)
- {
- free(ob->crd[vert].coord);
- }
- free(ob->crd);
- }
- ob->crd = NULL;
- }
- void POLINOM_Print(POLINOM *ob);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement