Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "main_viewer.h"
  5. #include "process_data.h"
  6. #include "record.h"
  7. #include "ADT_functions.h"
  8.  
  9.  
  10.  
  11. int main(int argc,char* argv[]){
  12.    
  13.     FILE *finput;
  14.     FILE *foutputcsv;
  15.     FILE *foutputkml;
  16.     size_t length;
  17.     size_t status;
  18.     char line[83]; 
  19.     char aux[60];
  20.     char inputfile[35];
  21.     char outputfile[10];
  22.     char format[4];
  23.     ADT_vector_t* vector;
  24.     void* ptr;
  25.     record_t* record;  
  26.     size_t i;
  27.  
  28.     if((status=process_arguments(argc,argv,&format))!=OK){
  29.         process_error(status);
  30.         return EXIT_FAILURE;
  31.     }
  32.    
  33.     if((finput=fopen(argv[ARG_INPUT_POSITION],"rt"))==NULL){
  34.         fprintf(stderr, "Error abriendo el archivo\n");
  35.         return EXIT_FAILURE;
  36.     }
  37.     if(format=="csv"){
  38.         if((foutputcsv=fopen(argv[ARG_OUTPUT_POSITION],"wt"))==NULL){
  39.             fprintf(stderr, "Error abriendo el archivo csv\n");
  40.             fclose(finput);
  41.              return EXIT_FAILURE;
  42.         }
  43.     }
  44.     if(format=="kml")
  45.     if((foutputkml=fopen(argv[ARG_OUTPUT_POSITION],"wt"))==NULL){
  46.         fprintf(stderr, "Error abriendo el archivo kml\n");
  47.         fclose(finput);
  48.         return EXIT_FAILURE;
  49.     }
  50.    
  51.  
  52.     vector = vector_new(sizeof(record_t));
  53.  
  54.     while(!feof(finput)){
  55.      
  56.  
  57.     if((status = read_line(finput,line)) != OK){
  58.         process_error(status);
  59.        
  60.         }
  61.  
  62.    
  63.     if((status = validateline(line)) != OK){
  64.         process_error(status);
  65.         return EXIT_FAILURE;
  66.     }
  67.    
  68.  
  69.     if(strncmp(line, FIELD_COMPARE, 6)!=0)
  70.         continue;
  71.     printf("esta es tu linea %s\n",line);
  72.    
  73.     record = vector_add(vector);
  74.    
  75.     if((status = split_line(line,record)) != OK){
  76.         process_error(status);
  77.         return EXIT_FAILURE;
  78.  
  79.     }
  80.     printf("i: %s \n", record->UTC);
  81. }
  82. ptr = vector_ptr(vector);
  83.  
  84.  
  85. qsort(ptr, vector_length(vector), sizeof(record_t), comparator);
  86.  
  87. for (i=0; i < vector_length(vector); i++) {
  88.         record_t* current = ((record_t*) vector_ptr(vector)) + i;
  89.         printf("id: %s, utc: %s\n", current->ID, current->UTC);
  90.     }
  91.    
  92.    
  93.     vector_free(vector);
  94.     puts("se alcanzo el final");
  95.    
  96. return EXIT_SUCCESS;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement