Pagini recente » Cod sursa (job #2862893) | Cod sursa (job #2033744) | Cod sursa (job #2445232) | Cod sursa (job #2959624) | Cod sursa (job #1342893)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char c;
int ok=0, print=0, k=0, i=0, n;
FILE *f, *out;
f = fopen("convertor.in","rt");
out = fopen("convertor.out","wt");
while (c!='}')
{
fscanf(f, "%c", &c);
if (c == ',' || c == '[') {
ok = 1;
}
else if (c == ':') {
ok = 0;
}
if (ok) {
if (c == '"' && print==0)
{
print = 1;
continue;
}
else if (c == '"')
{
print = 0;
k++;
fprintf(out,",");
}
}
if (print)
fprintf(out,"%c", c);
}
fseek(f, 0, SEEK_SET);
ok = 0;
fprintf(out,"\n");
while (!feof(f))
{
fscanf(f, "%c", &c);
if (c == ':' ) {
ok = 1;
}
else if (c == ',' || c == ']') {
ok = 0;
}
if (ok) {
if (c == '"' && print==0)
{
print = 1;
continue;
}
else if (c == '"')
{
print = 0;
fprintf(out,",");
i++;
if (i==k)
{
i=0;
fprintf(out,"\n");
}
}
}
if (print)
fprintf(out,"%c", c);
else if (!print && c>='0' && c<='9')
{
fseek(f,-1,SEEK_CUR);
fscanf(f,"%d",&n);
i++;
fprintf(out,"%d,",n);
if (i==k)
{
i=0;
fprintf(out,"\n");
}
}
}
return 0;
}