Cod sursa(job #1359592)

Utilizator maxu08Max Alexandru maxu08 Data 24 februarie 2015 23:50:47
Problema Convertor Scor 10
Compilator c Status done
Runda rosedu_cdl_2015 Marime 1.36 kb
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
	FILE *file,*out,*file2;
	char *str1 = malloc(110000*sizeof(char));
	char *str2 = malloc(110000*sizeof(char));
	int i = 0,j = 0;
	char c;

	file = fopen("convertor.in","r");
	out = fopen("convertor.out","w");

	c = fgetc(file);
	while(c != '}')
	{
		while(c != '"' && c != EOF)
			c = fgetc(file);
		c = fgetc(file);
		while(c != '"' && c != EOF)
		{
			str1[i] = c;
			c = fgetc(file);
			i++;
		}
		str1[i] = ',';
		i++;		
		
		while(c != ',' && c != '}')
			c = fgetc(file);
	}

	fprintf(out,"%s\n",str1);
	free(str1);
	fclose(file);
	file2 = fopen("convertor.in","r");

	c = fgetc(file2);
	while(c != ']' && c != EOF)
	{
		while(c != ':' && c != EOF)
			c = fgetc(file2);
		c = fgetc(file2);
		while(c == ' ' && c != EOF)
			c = fgetc(file2);
		if(c == '"' && c != EOF)
		{
			c = fgetc(file2);
			while(c != '"' && c != EOF)
			{
				str2[j] = c;
				j++;
				c = fgetc(file2);
			}
			str2[j] = ',';
			j++;
		}
		else
			if(c != EOF)
			{
				while(c != ',' && c != ' ')
				{
					str2[j] = c;
					j++;
					c = fgetc(file2);
				}
				str2[j] = ',';
				j++;
			}
		while(c != ':' && c != '}' && c != ']' && c != EOF)
			c = fgetc(file2);
		if(c == '}' && c != EOF) 
		{
			fprintf(out,"%s\n",str2);
			j = 0;
			free(str2);
			str2 = malloc(110000*sizeof(char));
		}
	}

	free(str2);
	fclose(file2);
	fclose(out);
}