Example #1
0
int main()
{
    char word[20];
    int i,k,nowlen;
    freopen("poj1035.txt","r",stdin);
    freopen("poj1035ans.txt","w",stdout);

    InitHash();

    n=0;
    while (scanf("%s",word) && word[0]!='#')
    {
        strcpy(dict[n].word,word);
        dict[n].id=n;
        dict[n].len=strlen(word);
        dict[n].weight=dict[n].len*100000+n;
        n++;
        Find(word,INSERT);
    }

    QSort(0,n-1);

    nowlen=0;
    memset(startpos,-1,sizeof(startpos));
    for (i=0;i<n;i++)
    {
        if (dict[i].len==nowlen) continue;
        else
        {
            nowlen=dict[i].len;
            startpos[nowlen]=i;
        }
    }
    
    while (scanf("%s",word) && word[0]!='#')
    {
        nowlen=strlen(word);
        cnt=0;
        if (Find(word,QUERY)!=-1) printf("%s is correct\n",word);
        else
        {
            printf("%s:",word);
            CheckLen(word,nowlen);
            if (nowlen==1) CheckLen(word,2);
            else if (nowlen==15) CheckLen(word,14);
            else
            {
                CheckLen(word,nowlen-1);
                CheckLen(word,nowlen+1);
            }
            QSort2(0,cnt-1);
            for (i=0;i<cnt;i++) printf(" %s",ans[i].word);
            printf("\n");
        }
    }
    
    return 0;
}
Example #2
0
static void
test_split(const char *n_flag)
{
#define CheckLen(x) do { \
	if (len != (x)) { \
		fprintf(stderr, "Wrong len %ld at line %d expected %d\n", (long int) len, __LINE__, (x)); \
		exit(1); \
	} \
	} while(0)

	char sql[80];
	char *buf = NULL;
	SQLLEN len;

	/* TODO test with VARCHAR too */
	sprintf(sql, "SELECT CONVERT(%sTEXT,'Prova' + REPLICATE('x',500))", n_flag);
	odbc_command(sql);

	CHKFetch("S");

	/* these 2 tests test an old severe BUG in FreeTDS */
	buf = ODBC_GET(1);
	CHKGetData(1, type, buf, 0, &len, "I");
	if (len != SQL_NO_TOTAL)
		CheckLen(505*lc);
	CHKGetData(1, type, buf, 0, &len, "I");
	if (len != SQL_NO_TOTAL)
		CheckLen(505*lc);
	buf = ODBC_GET(3*lc);
	CHKGetData(1, type, buf, 3 * lc, &len, "I");
	if (len != SQL_NO_TOTAL)
		CheckLen(505*lc);
	if (mycmp(buf, "Pr") != 0) {
		printf("Wrong data result 1\n");
		exit(1);
	}

	buf = ODBC_GET(16*lc);
	CHKGetData(1, type, buf, 16 * lc, &len, "I");
	if (len != SQL_NO_TOTAL)
		CheckLen(503*lc);
	if (mycmp(buf, "ovaxxxxxxxxxxxx") != 0) {
		printf("Wrong data result 2 res = '%s'\n", buf);
		exit(1);
	}

	buf = ODBC_GET(256*lc);
	CHKGetData(1, type, buf, 256 * lc, &len, "I");
	if (len != SQL_NO_TOTAL)
		CheckLen(488*lc);
	CHKGetData(1, type, buf, 256 * lc, &len, "S");
	CheckLen(233*lc);
	CHKGetData(1, type, buf, 256 * lc, &len, "No");

	odbc_reset_statement();

	/* test with varchar, not blob but variable */
	sprintf(sql, "SELECT CONVERT(%sVARCHAR(100), 'Other test')", n_flag);
	odbc_command(sql);

	CHKFetch("S");

	buf = ODBC_GET(7*lc);
	CHKGetData(1, type, buf, 7 * lc, NULL, "I");
	if (mycmp(buf, "Other ") != 0) {
		printf("Wrong data result 1\n");
		exit(1);
	}

	buf = ODBC_GET(5*lc);
	CHKGetData(1, type, buf, 20, NULL, "S");
	if (mycmp(buf, "test") != 0) {
		printf("Wrong data result 2 res = '%s'\n", buf);
		exit(1);
	}
	ODBC_FREE();

	odbc_reset_statement();
}