Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNING
- #include <stdio.h>
- #include <stdlib.h>
- //look into too these includes
- #include <crtdbg.h>
- #define _CRTDBG_MAP_ALLOC //need this to get the line identification
- //_CrtSetDbFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF; // in mian, after local
- //NB must b in debug
- enum{ RUNNING = 1 };
- struct Point
- {
- int x, y;
- };
- struct Line
- {
- Point start;
- Point end;
- };
- struct GraphicElement
- {
- enum{ SIZE = 256 };
- unsigned int numLines;
- Line* pLines;
- char name[SIZE];
- };
- typedef struct
- {
- unsigned int numGraphicElements;
- GraphicElement* pElements;
- }VectorGraphic;
- void InitVectorGraphic(VectorGraphic*);
- void AddGraphicElement(VectorGraphic*);
- void ReportVectorGraphic(VectorGraphic*);
- void CleanUpVectorGraphic(VectorGraphic*);
- VectorGraphic Image;
- int main()
- {
- char response;
- _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
- InitVectorGraphic(&Image);
- while (RUNNING)
- {
- printf("\nPlease select an option:\n");
- printf("1. Add a Graphic Element\n");
- printf("2. List the Graphic Elements\n");
- printf("q. Quit\n");
- printf("CHOICE: ");
- fflush(stdin);
- scanf("%c", &response);
- switch (response)
- {
- case '1':AddGraphicElement(&Image); break;
- case '2':ReportVectorGraphic(&Image); break;
- case 'q':CleanUpVectorGraphic(&Image); return 0;
- default:printf("Please enter a valid option\n");
- }
- printf("\n");
- }
- }
- void InitVectorGraphic(VectorGraphic* pImage)
- {
- pImage->pElements = NULL;
- pImage->numGraphicElements = 0;
- }
- void AddGraphicElement(VectorGraphic* pImage)
- {
- pImage->numGraphicElements++;
- pImage->pElements = (GraphicElement*)malloc(pImage->numGraphicElements * sizeof(GraphicElement));
- printf("Please enter the name of the new GraphicElement(<256 characters): ");
- scanf("%s", pImage->pElements->name);
- printf("How many lines are there in this new Graphic Element?:");
- scanf("%u", &pImage->pElements->numLines);
- pImage->pElements->pLines = (Line *)malloc(pImage->pElements->numLines* sizeof(Line));
- pImage->pElements->pLines->start.x = 0;
- pImage->pElements->pLines->start.y = 0;
- pImage->pElements->pLines->end.x = 0;
- pImage->pElements->pLines->end.y = 0;
- for (int i = 0; i < pImage->pElements->numLines; i++)
- {
- printf("\nPlease enter the x coord of the start point of line index %d:", i);
- scanf("%d", &pImage->pElements->pLines[i].start.x);
- printf("Please enter the y coord of the start point of line index %d:", i);
- scanf("%d", &pImage->pElements->pLines[i].start.y);
- printf("Please enter the x coord of the end point of line index %d:", i);
- scanf("%d", &pImage->pElements->pLines[i].end.x);
- printf("Please enter the y coord of the end point of line index %d:", i);
- scanf("%d", &pImage->pElements->pLines[i].end.y);
- printf("\n s.X:%d,s.Y: %d, e.X:%d, e.Y:%d ", pImage->pElements->pLines[i].start.x, pImage->pElements->pLines[i].start.y, pImage->pElements->pLines[i].end.x, pImage->pElements->pLines[i].end.y);
- }
- }
- void ReportVectorGraphic(VectorGraphic* pImage)
- {
- printf("\nVectorGraphic Report");
- for (int i = 0; i < pImage->numGraphicElements; i++){
- printf("\n Reporting Graphic Element #%d",i);
- printf("\n Graphic Element name: %s", pImage->pElements[i].name);
- /*for (int y = 1; y <= pImage->pElements->numLines; y++){
- pImage->pElements->pLines--;
- }*/
- for (int j = 0; j < pImage->pElements[i].numLines; j++)
- {
- printf("\n Line %d start x:%d", j, pImage->pElements->pLines[j].start.x);
- printf("\n Line %d start y:%d", j, pImage->pElements->pLines[j].start.y);
- printf("\n Line %d end x:%d", j, pImage->pElements->pLines[j].end.x);
- printf("\n Line %d end y:%d", j, pImage->pElements->pLines[j].end.y);
- }
- }
- }
- void CleanUpVectorGraphic(VectorGraphic* pImage)
- {
- free(pImage->pElements);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement