Cod sursa(job #1349193)

Utilizator george.ioana1995Ioana Alexandru george.ioana1995 Data 20 februarie 2015 00:41:06
Problema Convertor Scor 0
Compilator c Status done
Runda rosedu_cdl_2015 Marime 1.5 kb
#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);
    while(isalpha(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;
    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(cap,'}'))
            {
                eliminare(cap);
                eliminare(inf);
                cap[strlen(cap)]='\n';
                inf[strlen(inf)]='\n';
                fputs(cap,g);
                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;
}