Pagini recente » Cod sursa (job #1353042) | Cod sursa (job #1423307) | Cod sursa (job #1208617) | Cod sursa (job #2707522) | Cod sursa (job #1348313)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void eliminare(char s[1024])
{
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);
while(s[0]==' ')
strcpy(s,s+1);
for(i=0;i<strlen(s);i++)
if((s[i]==' ' && s[i-1]==',' )|| (s[i]==' ' && s[i+1]==','))
strcpy(s+i,s+i+1);
if(s[i-2]=='{' || s[i-2]=='}' || s[i-2]=='[' || s[i-2]=='"' || s[i-2]==']')
{s[i-2]=','; s[i-1]='\0';}
}
int main()
{
FILE* f;
FILE* g;
char s[1024],cap[1024],inf[1024];
char* cuv;
int ok=1;
int k;
if((f=fopen("convertor.txt","r"))==NULL)
{
printf("Nu s-a deschis fisierul.");
exit(1);
}
if((g=fopen("ed.txt","w"))==NULL)
{
printf("Nu s-a deschis fisierul.");
exit(1);
}
strcpy(cap,"");
strcpy(inf,"");
while(feof(f)==0)
{
fgets(s,1024,f);
cuv= strtok(s,",:");
k=1;
while(cuv!=NULL && cuv[0]!='\n')
{
if(k%2==0)
{strcat(inf,cuv); strcat(inf,",");}
else
if(ok)
{strcat(cap,cuv); strcat(cap,",");}
if(strchr(inf,'}'))
{
eliminare(inf);
eliminare(cap);
inf[strlen(inf)]='\n';
cap[strlen(cap)]='\n';
if(ok)
{
fputs(cap,g);
ok=0;
}
fputs(inf,g);
strcpy(inf,"");
strcpy(cap,"");
}
k++;
cuv=strtok(0,",:");
}
}
fclose(f);
fclose(g);
return 0;
}