Cod sursa(job #1360801)

Utilizator diana_ionDiana Ion diana_ion Data 25 februarie 2015 17:59:52
Problema Convertor Scor 100
Compilator cpp Status done
Runda rosedu_cdl_2015 Marime 1.69 kb
#include <iostream>
#include <stdio.h>
#include <fstream>

using namespace std;


int main()
{

    char ch;
    FILE *input;
    input = fopen("convertor.in", "r");
    FILE *output;
    output = fopen("convertor.out", "w");



    while((ch = fgetc(input)) != '}'){
        if(ch == '\"'){
            ch = fgetc(input);
            while(ch != '\"') {
                fputc(ch,output);
                ch = fgetc(input);
            }
           fputc(',', output);

        }
        else if(ch == ':'){
            ch = fgetc(input);
            while(ch == ' ' || ch == '\n'){
                ch = fgetc(input);
            }
            if ( ch == '"'){
                ch = fgetc(input);
                while(ch != '"'){
                    ch = fgetc(input);
                }
            }
        }

    }

    fseek(input, 0, SEEK_SET);

    while((ch = fgetc(input)) != EOF){

        if(ch == '{')
            fputc('\n', output);
        if(ch == ':'){
            ch = fgetc(input);
            while(ch == ' ' || ch == '\n'){
                ch = fgetc(input);
            }
            if(isdigit(ch))
                while(ch != ' ' && ch != ',' && ch != '}' && ch != '\n'){
                    fputc(ch, output);
                    ch = fgetc(input);
                }
            else
                if ( ch == '"'){
                    ch = fgetc(input);
                    while(ch != '"'){
                        fputc(ch, output);
                        ch = fgetc(input);
                    }
                }
                fputc(',', output);
        }

    }
    fclose(input);
    fclose(output);

    return 0;
}