Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- //int main(int argc, const char * argv[]) {
- struct node {
- string data;
- node* next = NULL;
- string tag;
- string key;
- node* prev = NULL;
- };
- struct Record{
- struct pair{
- string key;
- string value;
- }attributes[100];
- };
- int main(){
- char c;
- int attribute_count = 0;
- int line_count = 0;
- bool first_node = true;
- node *n , *head , *current;
- string tag,key;
- //open file
- ifstream file;
- file.open("/Users/nisij/Desktop/2430/hw/hw1/input.txt");
- if(file.fail()){
- cout << "Error File doesnot open or exists! " << endl;
- return 0;
- }
- //copy's to node
- while(!file.eof())
- {
- file >> c;
- if (c == '{')
- {
- attribute_count = 0;
- file >> c;
- while (c != '}')
- {
- while (c != ':')
- {
- tag = tag + c;
- file >> c;
- }
- file >> c;
- while (c != ',')
- {
- if(c == '}')
- break;
- key = key + c;
- file >> c;
- }
- if(c != '}')
- file >> c;
- attribute_count ++ ;
- //stores into doubly linked list
- if((first_node == true))
- {
- n = new node;
- n->tag = tag;
- n->key = key;
- current = n;
- head = n;
- head -> prev = NULL;
- n->next = NULL;
- tag.clear();
- key.clear();
- first_node = false;
- }else{
- n = new node;
- n->next = NULL;
- n->tag = tag;
- n->key = key;
- current->next = n;
- n->prev = current;
- current = n;
- tag.clear();
- key.clear();
- }
- }
- line_count ++;
- }
- }
- //re-setting te head;
- //current = head;
- //storing into array of struct line
- Record *Line = new Record[line_count];
- for (int i =0; i < line_count ;i++)
- {
- for ( int k =0; k<attribute_count ; k++)
- {
- cout << current->tag << ":";
- cout << current->key;
- current = current->next;
- cout <<endl;
- }
- }
- // for (int i = 0; i<line_count ; i++)
- // {
- // for(int k = 0; k<attribute_count; k++)
- // {
- //
- // Line[i].attributes[k].key = current->tag;
- // current = current->next;
- // cout << Line[i].attributes[k].key << endl;
- // Line[i].attributes[k].value =current->key;
- // cout << Line[i].attributes[k].value << endl;
- // if(current->next != NULL){
- // current = current->next;
- // }
- //
- // }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement