Pagini recente » Cod sursa (job #2199382) | Cod sursa (job #450215) | Cod sursa (job #1322436) | Cod sursa (job #1379287) | Cod sursa (job #1349209)
#include<stdio.h>
#include<string.h>
void eliminare(char s[])
{
int i;
for(i=0;i<strlen(s);i++)
if(s[i]=='"' || s[i]=='[' || s[i]==']' || s[i]=='{' || s[i]=='}' )
strcpy(s+i,s+i+1);
for(i=0;i<strlen(s);i++)
if((s[i]==' ' && s[i+1]==',') || (s[i]==' ' && s[i-1]==',') || (s[i]==',' && s[i+1]==','))
strcpy(s+i,s+i+1);
for(i=0;i<strlen(s)-1;i++)
if(s[i]==',' && s[i+1]==',')
strcpy(s+i,s+i+1);
while(s[0]=='[' || s[0]=='{' || s[0]==',' || s[0]==' '|| s[0]=='"')
strcpy(s,s+1);
}
int main()
{
FILE* f;
FILE* g;
char s[1024];
char* cuv;
char cap[1024],inf[1024];
int k;
int ok=1;
if((f=fopen("convertor.in","r"))==NULL)
{
printf("Nu s-a deshis fisierul.");
exit(1);
}
if((g=fopen("convertor.out","w"))==NULL)
{
printf("Nu s-a deshis fisierul.");
exit(1);
}
strcpy(cap,"");
strcpy(inf,"");
while(feof(f)==0)
{
fgets(s,2014,f);
s[strlen(s)-1]='\0';
cuv=strtok(s,",:");
k=1;
while(cuv!=NULL)
{
if(strchr(inf,'}') || strchr(cap,'}'))
{
eliminare(cap);
eliminare(inf);
cap[strlen(cap)]='\n';
inf[strlen(inf)]='\n';
if(ok){fputs(cap,g);ok=0;}
fputs(inf,g);
strcpy(cap,"");
strcpy(inf,"");
}
if(k%2==1)
{
strcat(cap,cuv);
strcat(cap,",");
}
else
{
strcat(inf,cuv);
strcat(inf,",");
}
cuv=strtok(0,",:");
k++;
}
}
return 0;
}