Pagini recente » Cod sursa (job #3130918) | Cod sursa (job #621838) | Cod sursa (job #2109530) | Cod sursa (job #3201632) | Cod sursa (job #1343445)
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdlib.h>
using namespace std;
void goto_next1(char c, int &ok)
{
char x;
while(x = getc(stdin))
{
if (x == '}') {ok = 0; break;}
if (x == c) break;
}
}
void goto_next2(char c, int &ok)
{
char x;
while(x = getc(stdin))
{
if (x == ']') {ok = 0; break;}
if (x == c) break;
}
}
void read_value1(char value[], char stop)
{
char x;
int i;
i = 0;
while (x = getc(stdin))
{
if (x == stop) break;
value[i] = x;
i++;
}
value[i] = '\0';
}
void read_value2(char value[], char stop)
{
char x, aux[1024] = {0};
int len;
while (x = getc(stdin))
{
if (x == stop)
{
read_value1(value, stop);
printf("%s,", value);
break;
}
else if (x != ' ' && x != '\n')
{
scanf("%s", aux);
len = strlen(aux);
if (aux[len-2] == '}') aux[len-2] = '\0';
else if (aux[len-1] == ',') aux[len-1] = '\0';
if (aux[len-1] == ']')
{
aux[len-2] = '\0';
printf("%c%s,", x, aux);
break;
}
printf("%c%s,", x, aux);
break;
}
}
}
int main()
{
int keys, ok, i;
char value[1024] = {0};
keys = 0;
ok = 1;
freopen("convertor.in", "r", stdin);
freopen("convertor.out", "w", stdout);
// get number of keys and first line
while (true)
{
goto_next1('"', ok);
if (!ok) break;
keys++;
read_value1(value, '"');
printf("%s,", value);
goto_next1(',', ok);
if (!ok) break;
}
printf("\n");
// get values
freopen("convertor.in", "r", stdin);
ok = 1;
while (true)
{
for (i = 0; i < keys; i++)
{
goto_next2(':', ok);
if (!ok) break;
value[1] = '\0';
read_value2(value, '"');
}
if (!ok) break;
printf("\n");
}
return 0;
}