I created this code in C where I inserted the coordinates of some points and with SVG I drew these points in the space connected by lines. all saved in an .html file to run in the browser. It's like a route scheme where I want to calculate between points.
The question is: So far I've inserted the points directly into my code. Now I want to give one up and read the X and Y points of another file that I created .csv, draw them in SVG and link them through lines, just like I have done so far. And when I change the file I want the program to update automatically.
In addition to the help, optimization and enhancement tips are also welcome as I am a programming enthusiast.
The following code is working and is an example of what I want to do:
#include <stdio.h>
#include <stdlib.h>
#define MyFileName "MEUARQUIVOSVG.html"
#define MapSize 500
int main (int argc, char *argv[])
{
FILE *html = fopen(MyFileName,"w+");
int coordenadas[5][2]={{50,50},{100,100},{150,320},{100,250},{400,300}};
char string[1024];
int i;
fprintf(html,"<html> \n <body>\n");
fprintf(html,"<h1>SVG em C</h1>");
fprintf(html,"<svg width=\"%d\" height=\"%d\">\n",MapSize,MapSize);
fprintf(html,"<rect width=\"%d\" height=\"%d\" style=\"fill:rgb(255,255,255);stroke-width:5;stroke:rgb(0,0,0)\" />\n",MapSize,MapSize);
for (i=0;i<5;i++) {
fprintf(html,"<circle cx=\"%d\" cy=\"%d\" r=\"3\" fill=\"blue\" />\n",coordenadas[i][0],coordenadas[i][1]);
sprintf(string,"%s%d,%d ",string,coordenadas[i][0],coordenadas[i][1]);
}
for (i=0;i<4;i++) {
fprintf(html,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"stroke:rgb(255,0,0);stroke-width:2\" />\n", coordenadas[i+1][0],coordenadas[i+1][1], coordenadas[i][0],coordenadas[i][1]);
}
fprintf(html,"<polyline points=\"%s\" style=\"fill:white;stroke:red;stroke-width:1\"",string);
fprintf(html,"</svg>\n");
fprintf(html,"</body> \n </html>");
fflush(html), fclose(html);
}
Thanks in advance!