Pagini recente » Cod sursa (job #407881) | Cod sursa (job #1633913) | Cod sursa (job #1785299) | Cod sursa (job #2143578) | Cod sursa (job #1359359)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *v = (char*) malloc( 1048576 * sizeof( char ) );
FILE *f = fopen("convertor.in" , "rt" );
unsigned short h = fread( v , sizeof(char) , 1048575 , f );
fclose( f );
v[h] = '\0';
char *tag = (char*) malloc(1024 * sizeof(char) );
unsigned short i = 0 , dt = 0;
const char *delim = ",";
char *tok = strtok ( v , delim );
f = fopen("convertor.out" , "wt" );
while ( tok[strlen(tok) - 1] != '}' )
{
i = 0;
while ( tok[i] != '"' )
i++;
i++;
while ( tok[i] != '"' )
{
fputc( tok[i] , f );
i++;
}
fputc( ',' , f );
i++;
while ( ( ( tok[i] < '1' ) || ( tok[i] > '9' ) ) && ( tok[i] != '"' ) )
i++;
if ( tok[i] == '"' )
{
i++;
while ( tok[i] != '"')
{
tag[dt] = tok[i];
dt++;
i++;
}
}
else
{
while ( (tok[i] > 47) && ( tok[i] < 58 ) )
{
tag[dt] = tok[i];
i++;
dt++;
}
}
tag[dt] = ',';
dt++;
tok = strtok( NULL , delim );
}
i = 0;
while ( tok[i] != '"' )
i++;
i++;
while ( tok[i] != '"' )
{
fputc( tok[i] , f );
i++;
}
fputc( ',' , f );
i++;
while ( ( ( tok[i] < '1' ) || ( tok[i] > '9' ) ) && ( tok[i] != '"' ) )
i++;
if ( tok[i] == '"' )
{
i++;
while ( tok[i] != '"')
{
tag[dt] = tok[i];
dt++;
i++;
}
}
else
{
while ( (tok[i] > 47) && ( tok[i] < 58 ) )
{
tag[dt] = tok[i];
i++;
dt++;
}
}
tag[dt] = ',';
dt++;
tok = strtok( NULL , delim );
tag[dt] = '\n';
dt++;
tag[dt] = '\0';
fprintf( f , "\n%s" , tag );
free(tag);
unsigned char t;
while ( tok != NULL )
{
i = 1;
t = 2;
while ( t )
{
if ( tok[i] == '"' )
t--;
i++;
}
while ( ( ( tok[i] < '1' ) || ( tok[i] > '9' ) ) && ( tok[i] != '"' ) )
i++;
if ( tok[i] == '"' )
{
i++;
while ( tok[i] != '"')
{
fputc( tok[i] , f );
i++;
}
}
else
{
while ( (tok[i] > 47) && ( tok[i] < 58 ) )
{
fputc( tok[i] , f );
i++;
}
}
fputc( ',' , f );
if ( tok[strlen(tok) - 1] == '}' )
fputc( '\n' , f );
tok = strtok( NULL , delim );
}
free( v );
fclose( f );
}