Hey guys,
i need urgent some help as I'm running out of hours to give up my program.
I need to write a program which reads coordinates from different places from one binary file, sort the accordion the ID, and saves them into one KML file (Keyhole Markup Language).
Input will be through command prompt done.
Data structure:
In binary file is not defined number of data records. Each of them has Header with defined Length and one Content who's length can variate.
http://img832.imageshack.us/img832/3...20117at455.png
Internal memory:
Readed files will be intern in one linked list saved. Independent from sorting in binary file, all Data records must be in program flow ascending according to Identifikator sorted.
Output:
The sorted list will be in one Text file saved. The name of the text file will be the same as the name of input file just the ending must be changed from .db to .kml.
The text file begins with Header:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
For each data record must be Template used (text in [ ] must be changed with data recordīs facts.
Code:
<Placemark>
<name>[Name]</name>
<description>[Beschreibung]</description>
<Point>
<coordinates>[Longitude],[Latitude],0</coordinates>
</Point>
</Placemark>
The file ends with Footer:
So until now this is what I have got:
Code:
//
#include "stdafx.h"
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
struct InputStructHeader
{
unsigned int Identifikator ;
double Latitude ;
double Longitude ;
unsigned int Length ;
};
struct InputStructContent
{
char Name[255] ;
char Beschreibung[255] ;
};
// lets put those in one data structure so its easier to work with it
struct Everything
{
struct InputStructHeader header;
struct InputStructContent content;
};
// now the list: the list have all informations from up and has a pointer to next and prevois. If there is not a next or prevous then NULL
struct LinkedListStruct
{
struct Everything* data;
struct LinkedListStruct* previous;
struct LinkedListStruct* next;
};
int main(int argc, char* argv[])
{
// Lets open the db file:
char inputFilename[]= "C:\Users\Dean\Desktop\DexSolution\DexProject\inout\ass3_test_V004\ass3_01.db"; //this is in one zip file
FILE* inFilePointer ;
inFilePointer = fopen( inputFilename, "rb" );
// Now the list
// Lets create the firs member of list:
struct LinkedListStruct* first;
first = (struct LinkedListStruct*) malloc( sizeof(struct LinkedListStruct) );
// Lets create some facts wich this member contains:
struct Everything* everything;
everything = (struct Everything*) malloc( sizeof(struct Everything ) );
// read facts from file:
fread( &everything->header.Identifikator , sizeof(unsigned int ), 1, inFilePointer ); // here we read one fact which is long "unsigned int" and save it to everything->header.Identifikator
fread( &everything->header.Latitude , sizeof(double ), 1, inFilePointer );
fread( &everything->header.Longitude , sizeof(double ), 1, inFilePointer );
fread( &everything->header.Length , sizeof(unsigned int ), 1, inFilePointer );
fread( &everything->content.Name , sizeof(char ), everything->header.Length, inFilePointer );
// now lets add those facts to list:
first->data = everything;
// its first, so it doest not have any behind:
first->previous = NULL;
// for now its the onlier one so there is no after:
first->next = NULL;
// lets create second member:
struct LinkedListStruct* second;
second = (struct LinkedListStruct*) malloc( sizeof(struct LinkedListStruct) );
// and facts for second member:
struct Everything* everything2;
everything2 = (struct Everything*) malloc( sizeof(struct Everything ) );
// we read facts from file:
fread( &everything2->header.Identifikator , sizeof(unsigned int ), 1, inFilePointer );
fread( &everything2->header.Latitude , sizeof(double ), 1, inFilePointer );
fread( &everything2->header.Longitude , sizeof(double ), 1, inFilePointer );
fread( &everything2->header.Length , sizeof(unsigned int ), 1, inFilePointer );
fread( &everything2->content.Name , sizeof(char ), everything2->header.Length, inFilePointer );
// now lets add those facts to list:
second->data = everything2;
// behind is first:
second->previous = first;
// there no next:
second->next = NULL;
// close everything:
fclose(inFilePointer);
free( first );
free( second );
free( everything );
free( everything2 );
return 0;
}
/*
First sub program should read those 6 facts from file and save them to structure, e.g.:
bool ReadDataFromFile( FILE* fajl, struct Everything* every);
Second sub program will all those facts put in Linked list:
bool InsertAfter( LinkedListStruct* existingNode, LinkedListStruct* nexNode);
Then i think I need something which checks if there is more files...?
do
{
thereIsMoreFiles = ReadDataFromFile( fileP, everythingX );
InsertAfter( prevouisMemberOfList , newMemberOfList );
}
while( thereIsMoreFiles);
Please help me as I have only 24 hours left to give up this program.
THANK YOU VERY MUCH