LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 01-17-2012, 10:17 AM   #1
dexter910
LQ Newbie
 
Registered: Jan 2012
Posts: 8

Rep: Reputation: Disabled
Exclamation Read from binary file and save it as KML file in C


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:

Code:
 </Document>
</kml>

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
 
Old 01-17-2012, 02:01 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Duplicate post.

Please follow discussion here:

http://www.linuxquestions.org/questi...5/#post4577131

closing thread.
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C, howto read binary file into buffer Scrag Programming 24 11-27-2014 05:32 PM
Reading from binary file and saving elements to KML file in C dexter910 Programming 9 01-18-2012 11:06 AM
Problem to Read Binary File with gfortran kdurgarao Programming 1 10-12-2009 02:26 AM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 05:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration