Pagini recente » Cod sursa (job #503414) | Istoria paginii runda/ceoi_1 | Cod sursa (job #2754583) | Rating Andrei Fratila (xAnymous) | Cod sursa (job #1356724)
#include<stdio.h>
#include<string.h>
int main(){
FILE *f = fopen("convertor.in", "r"), *out = fopen("convertor.out","w");
char line[1025];
char text[8192];
char copy[2048];
char value[256];
int chei = 0;
int i, j;
int print = 0;
int finished = 0;
while(fgets(line, 1025, f) != NULL){
line[strlen(line) - 1] = 0;
if(strchr(line, '}') != NULL){
strcat(text, line);
//afisare chei
if(chei == 0){
strcpy(copy, text);
char *key = strtok(copy, ",");
while(key != NULL && strlen(key) > 2 && !finished){
if(strchr(key, '}'))
finished = 1;
print = 0;
for(i = 0; i < strlen(key); i++){
if(print == 1 && key[i] != '"')
fprintf(out,"%c", key[i]);
if(key[i] == '"'){
if(print == 0)
print = 1;
else
break;
}
}
fprintf(out,",");
key = strtok(NULL, ",");
}
chei = 1;
}
//afisare valori
char *val = strtok(text, ",");
while(val != NULL && strlen(val) > 1){
/*puts("\nvaloare:");*/
/*puts(val);*/
/*puts("");*/
if(strchr(val, '{') != NULL)
fprintf(out,"\n");
//inaintam pana la primul :
for(i = 0; i < strlen(val) ; i++){
if(val[i] == ':')
break;
}
i++;
//ignoram leading spaces
while(val[i] == ' ')
i++;
//daca e string, ignoram ghilimeaua
if(val[i] == '"')
i++;
while(val[i] != '"' && i < strlen(val)){
fprintf(out,"%c", val[i]);
i++;
}
val = strtok(NULL, ",");
fprintf(out,",");
}
text[0] = 0;
/*puts("*********gata linie**********");*/
} else {
strcat(text, line);
}
}
return 0;
}