Guest User

Untitled

a guest
Jan 3rd, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define CONTLENGHT 161
  6.  
  7. struct eintrag
  8. {
  9.     unsigned int ID;
  10.     double lat;
  11.     double log;
  12.     unsigned int contentlength;
  13.     char *name;
  14.     char *description;
  15. };
  16.  
  17. char *readlist()
  18. {
  19.     //testcase
  20.     struct eintrag test[2];
  21.     test[0].name = "Stadt";
  22.     test[0].description = "Das hier ist eine Stadt";
  23.     test[0].lat = 154;
  24.     test[0].log = 60;
  25.     test[0].contentlength = 28;
  26.     test[1].name = "Ort";
  27.     test[1].description = "Das hier ist ein Ort";
  28.     test[1].lat = 125;
  29.     test[1].log = 88;
  30.     test[1].contentlength = 25;
  31.     //-----------------------------------------------------------------------------
  32.     int i;
  33.     int anzahl = 2;
  34.     int contlen = 0;
  35.     for (i = 0; i < anzahl; i++)
  36.     {
  37.         contlen = contlen + CONTLENGHT + test[i].contentlength + 20;
  38.     }
  39.     char *cont = malloc(contlen * sizeof(char));
  40.     cont[0] = '\0';
  41.     for (i = 0; i < anzahl; i++)
  42.     {
  43.         char *buffer = malloc(CONTLENGHT + test[i].contentlength + 20);
  44.         sprintf(buffer, " <Placemark>\n <name>%s</name>\n <description>"
  45.             "%s</description>\n <Point>\n <coordinates>"
  46.             "%f,%f,0</coordinates>\n </Point>\n </Placemark>\n",
  47.             test[i].name, test[i].description, test[i].log, test[i].lat);
  48.         strcat(cont,buffer);
  49.         free(buffer);
  50.     }
  51.     return cont;
  52. }
  53.  
  54. int test(char *content)
  55. {
  56.     char *header;
  57.     char *footer;
  58.     header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  59.         "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n<Document>\n";
  60.     footer = "</Document>\n</kml>\n";
  61.     FILE *fp;
  62.     fp = fopen ("file.kml", "w");
  63.     fprintf(fp, "%s%s%s" , header, content, footer);
  64.     fclose(fp);
  65.     return 0;
  66. }
  67.  
  68. int main()
  69. {
  70.     char *x = readlist();
  71.     test(x);
  72.     printf("\nData Stored!!!!!! \n\n %s", x);
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment