Pagini recente » Cod sursa (job #1350791) | Cod sursa (job #1874439) | Cod sursa (job #1532991) | Monitorul de evaluare | Cod sursa (job #1344087)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define NMAX 4096000
int main()
{
char *aux, *head, *headaux, JSON[NMAX], JSON1[NMAX];
int i = 0, k;
FILE *f, *g;
f = fopen ("convertor.in", "r" ) ;
g = fopen ("convertor.out", "w") ;
fscanf(f,"%[^&]s",JSON) ;
fscanf(f,"%[^&]s",JSON1) ;
head = strtok(JSON,"}") ;
headaux = strtok(head,",{:") ;
while ( headaux != NULL )
{
if ( i % 2 == 1 )
{
int j1 ,j2, j;
for ( j = 0 ; j < strlen(headaux) ; j++ )
{
if ( headaux[j] == '"') j2 = j ;
}
for ( j = strlen(headaux) - 1 ; j >= 0 ; j-- )
{
if ( headaux[j] == '"' ) j1 = j ;
}
for ( j = j1 + 1 ; j < j2 ; j++ )
{
fprintf(g,"%c",headaux[j]);
}
fprintf(g,",");
}
headaux = strtok(NULL,",{:");
i = i + 1 ;
}
k = i ;
i = 0 ;
aux = strtok(JSON1,",:");
while ( aux != NULL )
{
if ( i % 2 == 1 )
{
int j1 = 0, j2 = 0, j;
for ( j = 0 ; j < strlen(aux) ; j++ )
{
if ( aux[j] == '"') j2 = j ;
}
for ( j = strlen(aux) - 1 ; j >= 0 ; j-- )
{
if ( aux[j] == '"') j1 = j ;
}
if ( j1 != 0 && j2 != 0 )
for ( j = j1 + 1 ; j < j2 ; j++ )
{
fprintf(g,"%c",aux[j]);
}
if ( j2 == 0 && j1 == 0 )
for ( j = 0 ; j < strlen(aux) ; j++ )
{
if ( isdigit( aux[j] ) ) fprintf(g,"%c", aux[j] ) ;
}
fprintf(g,",");
}
if ( i % (k - 1) == 0 ) fprintf(g,"\n");
aux = strtok(NULL,",:");
i = i + 1 ;
}
fprintf(g,"\n");
fclose(f);
fclose(g);
return 0;
}