Advertisement
Guest User

second

a guest
Feb 25th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.39 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6. using namespace std;
  7.  
  8. //int main(int argc, const char * argv[]) {
  9.  
  10. struct node {
  11.     string data;
  12.     node* next = NULL;
  13.     string tag;
  14.     string key;
  15.     node* prev = NULL;
  16. };
  17.  
  18.  
  19. struct Record{
  20.     struct pair{
  21.         string key;
  22.         string value;
  23.     }attributes[100];
  24. };
  25.  
  26.  
  27.  
  28. int main(){
  29.     char c;
  30.    
  31.     int attribute_count = 0;
  32.     int line_count = 0;
  33.     bool first_node = true;
  34.     node *n , *head , *current;
  35.     string tag,key;
  36.    
  37.     //open file
  38.     ifstream file;
  39.     file.open("/Users/nisij/Desktop/2430/hw/hw1/input.txt");
  40.    
  41.     if(file.fail()){
  42.         cout << "Error File doesnot open or exists! " << endl;
  43.         return 0;
  44.     }
  45.    
  46.     //copy's to node
  47.     while(!file.eof())
  48.     {
  49.        
  50.         file >> c;
  51.        
  52.         if (c == '{')
  53.         {
  54.             attribute_count = 0;
  55.             file >> c;
  56.             while (c != '}')
  57.             {
  58.                 while (c != ':')
  59.                 {
  60.                    
  61.                     tag = tag + c;
  62.                     file >> c;
  63.                 }
  64.                
  65.                 file >> c;
  66.                 while (c != ',')
  67.                 {
  68.                     if(c == '}')
  69.                         break;
  70.                     key = key + c;
  71.                     file >> c;
  72.                    
  73.                 }
  74.                 if(c != '}')
  75.                 file >> c;
  76.                 attribute_count ++ ;
  77.                 //stores into doubly linked list
  78.                
  79.                 if((first_node == true))
  80.                 {
  81.                     n = new node;
  82.                     n->tag = tag;
  83.                     n->key = key;
  84.                     current  = n;
  85.                     head = n;
  86.                     head -> prev = NULL;
  87.                     n->next = NULL;
  88.                     tag.clear();
  89.                     key.clear();
  90.                     first_node = false;
  91.                 }else{
  92.                     n = new node;
  93.                     n->next = NULL;
  94.                     n->tag = tag;
  95.                     n->key = key;
  96.                     current->next = n;
  97.                     n->prev = current;
  98.                     current = n;
  99.                     tag.clear();
  100.                     key.clear();
  101.                 }
  102.             }
  103.             line_count ++;
  104.         }
  105.     }
  106.     //re-setting te head;
  107.     //current = head;
  108.     //storing into array of struct line
  109.     Record *Line = new Record[line_count];
  110.    
  111.     for (int i =0; i < line_count ;i++)
  112.     {
  113.         for ( int k =0; k<attribute_count ; k++)
  114.         {
  115.             cout << current->tag << ":";
  116.             cout << current->key;
  117.             current = current->next;
  118.             cout <<endl;
  119.            
  120.         }
  121.     }
  122.    
  123.    
  124. //    for (int i = 0; i<line_count ; i++)
  125. //    {
  126. //        for(int k = 0; k<attribute_count; k++)
  127. //        {
  128. //
  129. //            Line[i].attributes[k].key = current->tag;
  130. //            current = current->next;
  131. //            cout <<  Line[i].attributes[k].key << endl;
  132. //            Line[i].attributes[k].value =current->key;
  133. //            cout <<  Line[i].attributes[k].value << endl;
  134. //            if(current->next != NULL){
  135. //            current = current->next;
  136. //            }
  137. //
  138. //        }
  139.    
  140.      
  141.  
  142.        
  143.    
  144.  
  145.    
  146.    
  147.    
  148.    
  149.     return 0;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement