| 发表于:2007-08-23 01:31:399楼 得分:0 |
vc的代码好多的,几千行....贴不完 我就贴第一个函数好了,chenhui530帮我看看,我觉得我调用后returnlong那个返回-1是错的..应该就没有执行 loadalldidata函数成功,应该是这里有问题. vb里面声明和调用方式我查了很多资料,也尝试了不同的方式,然后觉得还是myjian(嗷嗷叫的老马--无视无视~~)说的对,不过还是有点糊涂的. 下面是vc的部分代码 -------------------------------------------- /************************************************************************/ /* 从文件中load所有di数据 */ /************************************************************************/ int loadalldidata(searchdidata &searchdata, char *strengfilename, char *strchinfilename) { file *pfeng = 0; file *pfchin = 0; long lheaderitemsize = 0; long lheadernumber = 0; long lposoffset = 0; long lposengoffset = 0; long lposchinoffset = 0; int nsumcount = 0; int ndatacount = 0; char buf[256]; unsigned short wchin[256]; long lfirstposeng = 0; long lfirstposchin = 0; if ((pfeng = fopen(strengfilename, "rb ")) == 0) { printf( "error open eng "); return -1; } if ((pfchin = fopen(strchinfilename, "rb ")) ==0) { printf( "error open chinse "); return -1; } memset(buf, 0x00, sizeof(buf)); if (fgets(buf, sizeof(buf), pfeng) == 0) { fclose(pfeng); return -2; } buf[strlen(buf)-1] = '\0 '; lheadernumber = atol(buf); memset(buf, 0x00, sizeof(buf)); if (fgets(buf, sizeof(buf), pfeng) == 0) { fclose(pfeng); return -2; } buf[strlen(buf)-1] = '\0 '; lheaderitemsize = atol(buf); for (int i =0; i <lheadernumber; i++) { memset(buf, 0x00, sizeof(buf)); if (fgets(buf, sizeof(buf), pfeng) == 0) { fclose(pfeng); return -2; } searchdata.chrpos[i].ch = getcharacterletter(buf); getfstpostion(buf, ndatacount, lposengoffset, lposchinoffset); if (i == 0) { lfirstposeng = lposengoffset; lfirstposchin = lposchinoffset; } searchdata.chrpos[i].ncount = ndatacount; searchdata.chrpos[i].nfsrpos = nsumcount; nsumcount += ndatacount; } fseek(pfeng, lfirstposeng, seek_set); fseek(pfchin, lfirstposchin, seek_set); for (i =0; i <nsumcount; i++) { memset(buf, 0x00, sizeof(buf)); if (fgets(buf, sizeof(buf), pfeng) == 0) { fclose(pfeng); fclose(pfchin); return -1; } buf[strlen(buf)-1] = '\0 '; memset(wchin, 0x00, sizeof(wchin)); if (fgetws(wchin, sizeof(wchin), pfchin) == 0) { fclose(pfeng); fclose(pfchin); return -1; } wchin[wcslen(wchin)-1] = 0x00; strcpy(searchdata.data[i].streng, buf); wcscpy(searchdata.data[i].strchinese, wchin); } fclose(pfeng); fclose(pfchin); return 1; } ------------------------------------------ /************************************************************************/ /* di写入内存结构 */ /************************************************************************/ typedef struct tysearchdi { position chrpos[27]; eledi data[11000]; }searchdidata | | |
|