Pagini recente » Cod sursa (job #822802) | Cod sursa (job #52155) | Cod sursa (job #1351900) | Cod sursa (job #2435336) | Cod sursa (job #1359426)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void eliminare(char s[])
{
int i;
for(i=0;i<strlen(s);i++)
{
while(s[i]=='"' && s[i+1]==' ')
strcpy(s+i+1,s+i+2);
while(s[i]==',' && s[i+1]==' ')
strcpy(s+i+1,s+i+2);
if(s[i]=='[' || s[i]==']' || s[i]=='{' || s[i]=='}')
strcpy(s+i,s+i+1);
}
for(i=0;i<strlen(s);i++)
{
while(s[i-1]=='"' && s[i]==' ')
strcpy(s+i,s+i+1);
}
for(i=0;i<strlen(s);i++)
if(s[i]=='"')
strcpy(s+i,s+i+1);
while(isalpha(s[0])==0 && isdigit(s[0])==0)
strcpy(s,s+1);
}
int main()
{
FILE* f;
FILE* g;
char s[1000000],c;
char cap[100000],inf[100000];
char* cuv;
int l,ok;
int d;
if((f=fopen("convertor.in","r"))==NULL)
{
printf("Nu s-a deschis fisierul.");
exit(1);
}
if((g=fopen("convertor.out","w"))==NULL)
{
printf("Nu s-a deschis fisierul.");
exit(1);
}
l=0;
ok=1;
strcpy(cap,"");
strcpy(inf,"");
while(feof(f)==0)
{
c=fgetc(f);
if(c=='}')
{
s[strlen(s)-1]='\0';
d=1;
cuv=strtok(s,",:");
while(cuv!=NULL)
{
if(d%2==1)
{strcat(cap,cuv); strcat(cap,",");}
else
{strcat(inf,cuv); strcat(inf,",");}
cuv=strtok(NULL,",:");
d++;
}
cap[strlen(cap)]='\n';
inf[strlen(inf)]='\n';
if(ok){eliminare(cap); fputs(cap,g); ok=0; fprintf(f,"\n");}
eliminare(inf);
fputs(inf,g);
fprintf(f,"\n");
l=0;
s[l]='\0';
strcpy(cap,"");
strcpy(inf,"");
}
else
{
if(c!='\n')
{s[l]=c;l++;}
}
}
return 0;
}