Pagini recente » Cod sursa (job #2381249) | Cod sursa (job #1059258) | Cod sursa (job #1920128) | Cod sursa (job #3271121) | Cod sursa (job #1358444)
//
// main.cpp
// CDL_convertor
//
// Created by Alex Petrache on 24/02/15.
// Copyright (c) 2015 Alex Petrache. All rights reserved.
//
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, const char * argv[]) {
ifstream f("convertor.in");
ofstream g("convertor.out");
// ifstream f("/Users/alexpetrache/Documents/Programare/Xcode/CDL_convertor/CDL_convertor/convertor.in");
// ofstream g("/Users/alexpetrache/Documents/Programare/Xcode/CDL_convertor/CDL_convertor/convertor.out");
char c;
string keys;
string values;
bool expectWhat=0; //0 key, 1 value
bool firstTime=true;
while(f>>c){
// cout<<c;
if(c=='"'){
//daca vreau cheie
if(expectWhat==0){
do{
f.get(c);
if(c!='"')
keys.push_back(c);
}while(c!='"');
keys.push_back(',');
expectWhat=1;
}else{
do{
f.get(c);
if(c!='"')
values.push_back(c);
}while(c!='"');
values.push_back(',');
expectWhat=0;
}
}
else if(c>='0' && c<='9' && expectWhat){
values.push_back(c);
do{
f.get(c);
if(c>='0' && c<='9')
values.push_back(c);
}while(c>='0' && c<='9');
values.push_back(',');
expectWhat=0;
}
if(c=='}'){
if(firstTime)
cout<<keys<<'\n';
cout<<values<<endl;
keys="";
values="";
firstTime=false;
}
}
return 0;
}