Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define CONTLENGHT 161
- struct eintrag
- {
- unsigned int ID;
- double lat;
- double log;
- unsigned int contentlength;
- char *name;
- char *description;
- };
- char *readlist()
- {
- //testcase
- struct eintrag test[2];
- test[0].name = "Stadt";
- test[0].description = "Das hier ist eine Stadt";
- test[0].lat = 154;
- test[0].log = 60;
- test[0].contentlength = 28;
- test[1].name = "Ort";
- test[1].description = "Das hier ist ein Ort";
- test[1].lat = 125;
- test[1].log = 88;
- test[1].contentlength = 25;
- //-----------------------------------------------------------------------------
- int i;
- int anzahl = 2;
- int contlen = 0;
- for (i = 0; i < anzahl; i++)
- {
- contlen = contlen + CONTLENGHT + test[i].contentlength + 20;
- }
- char *cont = malloc(contlen * sizeof(char));
- cont[0] = '\0';
- for (i = 0; i < anzahl; i++)
- {
- char *buffer = malloc(CONTLENGHT + test[i].contentlength + 20);
- sprintf(buffer, " <Placemark>\n <name>%s</name>\n <description>"
- "%s</description>\n <Point>\n <coordinates>"
- "%f,%f,0</coordinates>\n </Point>\n </Placemark>\n",
- test[i].name, test[i].description, test[i].log, test[i].lat);
- strcat(cont,buffer);
- free(buffer);
- }
- return cont;
- }
- int test(char *content)
- {
- char *header;
- char *footer;
- header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n<Document>\n";
- footer = "</Document>\n</kml>\n";
- FILE *fp;
- fp = fopen ("file.kml", "w");
- fprintf(fp, "%s%s%s" , header, content, footer);
- fclose(fp);
- return 0;
- }
- int main()
- {
- char *x = readlist();
- test(x);
- printf("\nData Stored!!!!!! \n\n %s", x);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment