ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1269. Obscene Words Filter

Access violation on #5
Posted by efpies [SPbSETU] 11 Jul 2009 06:09
My program crashes on #5. My input func ignoring EOF symbol and I using my own (because I'm a starter ;)) search in strings (that's below). I can't find test that crash my prog. Can you give me hint what's wrong or give test?

//-----------------------------
int srch(char *str, char *cond)
{
        char *blk;
        int i, j;
        blk = (char*)malloc((strlen(cond)+1)*sizeof(char));
        blk[strlen(cond)] = '\0';

        for(i = 0; i < strlen(str)-strlen(cond)+1; i++)
        {
                for(j = 0; j < strlen(cond); j++)
                        blk[j] = str[i+j];

                if(!strcmp(blk,cond))
                        return i+1;
        }

        return 0;
}

void parse(char **e, int Ecount, char **t, int Tcount)
{
        int i, j, pos;

        for(i = 0; i < Tcount; i++)
                for(j = 0; j < Ecount; j++)
                        if(strlen(e[j]) && strlen(t[i]) && (pos = srch(t[i],e[j])))
                        {
                                printf("%d %d",i+1,pos);
                                return;
                        }

        puts("Passed");
}