请高手帮忙分析一下面的代码有什么问题
谢谢typedef struct keywords_stru
{
char substr[30];
char sfztjm[8];
char zdztjm[8];
char ch[12];
char xx[4];
char wjm[30];
struct keywords_stru *next;
}KeyW_Stru;typedef struct ljarray
{
KeyW_Stru *plheader;
}LJB;LJB SPZLJB[MAXARRAY];
int chkqs(HYWL_stru *jd,int line,char thwjm[])
{
KeyW_Stru *Newp,*Current,*Prior;
char newstr[128],oldstr[128];
memset(thwjm,0,sizeof(thwjm));
if ( (Newp=(KeyW_Stru *)malloc(sizeof(KeyW_Stru)))==NULL )
{
printf("Out of Memory in chkqs()!\n");
return -1;
}
strcpy(Newp->substr,jd->wjm);
Newp->substr[9]=0;
strcpy(Newp->wjm,jd->wjm);
strcpy(Newp->sfztjm,jd->sfztjm);
strcpy(Newp->zdztjm,jd->zdztjm);
strcpy(Newp->ch,jd->ch);
strcpy(Newp->xx,jd->xx);
Newp->next=NULL;
if ( SPZLJB[line].plheader == NULL )
{
SPZLJB[line].plheader = Newp;
Newp->next=NULL;
return 0;
}
Current=SPZLJB[line].plheader;
memset(newstr,0,sizeof(newstr));
memset(oldstr,0,sizeof(oldstr));
sprintf(newstr,"%s\t%s\t%s\t%s\t%s",Newp->substr,Newp->sfztjm,Newp->zdztjm,Newp->ch,Newp->xx);
sprintf(oldstr,"%s\t%s\t%s\t%s\t%s",Current->substr,Current->sfztjm,Current->zdztjm,Current->ch,Current->xx);
while(Current->next!=NULL&&strcmp(newstr,oldstr)>0)
{
memset(oldstr,0,sizeof(oldstr));
sprintf(oldstr,"%s\t%s\t%s\t%s\t%s",Current->substr,Current->sfztjm,Current->zdztjm,Current->ch,Current->xx);
Prior=Current;
Current=Current->next;
} if(strcmp(newstr,oldstr)==0)
{
strcpy(thwjm,Current->wjm);
return 1;
}
if(strcmp(newstr,oldstr)<0)
{
if(SPZLJB[line].plheader==Current) SPZLJB[line].plheader =Newp;
else Prior->next=Newp;
Newp->next=Current;
return 2;
}
Current->next=Newp;
Newp->next=NULL;
return 3;
}
谢谢typedef struct keywords_stru
{
char substr[30];
char sfztjm[8];
char zdztjm[8];
char ch[12];
char xx[4];
char wjm[30];
struct keywords_stru *next;
}KeyW_Stru;typedef struct ljarray
{
KeyW_Stru *plheader;
}LJB;LJB SPZLJB[MAXARRAY];
int chkqs(HYWL_stru *jd,int line,char thwjm[])
{
KeyW_Stru *Newp,*Current,*Prior;
char newstr[128],oldstr[128];
memset(thwjm,0,sizeof(thwjm));
if ( (Newp=(KeyW_Stru *)malloc(sizeof(KeyW_Stru)))==NULL )
{
printf("Out of Memory in chkqs()!\n");
return -1;
}
strcpy(Newp->substr,jd->wjm);
Newp->substr[9]=0;
strcpy(Newp->wjm,jd->wjm);
strcpy(Newp->sfztjm,jd->sfztjm);
strcpy(Newp->zdztjm,jd->zdztjm);
strcpy(Newp->ch,jd->ch);
strcpy(Newp->xx,jd->xx);
Newp->next=NULL;
if ( SPZLJB[line].plheader == NULL )
{
SPZLJB[line].plheader = Newp;
Newp->next=NULL;
return 0;
}
Current=SPZLJB[line].plheader;
memset(newstr,0,sizeof(newstr));
memset(oldstr,0,sizeof(oldstr));
sprintf(newstr,"%s\t%s\t%s\t%s\t%s",Newp->substr,Newp->sfztjm,Newp->zdztjm,Newp->ch,Newp->xx);
sprintf(oldstr,"%s\t%s\t%s\t%s\t%s",Current->substr,Current->sfztjm,Current->zdztjm,Current->ch,Current->xx);
while(Current->next!=NULL&&strcmp(newstr,oldstr)>0)
{
memset(oldstr,0,sizeof(oldstr));
sprintf(oldstr,"%s\t%s\t%s\t%s\t%s",Current->substr,Current->sfztjm,Current->zdztjm,Current->ch,Current->xx);
Prior=Current;
Current=Current->next;
} if(strcmp(newstr,oldstr)==0)
{
strcpy(thwjm,Current->wjm);
return 1;
}
if(strcmp(newstr,oldstr)<0)
{
if(SPZLJB[line].plheader==Current) SPZLJB[line].plheader =Newp;
else Prior->next=Newp;
Newp->next=Current;
return 2;
}
Current->next=Newp;
Newp->next=NULL;
return 3;
}
解决方案 »
- 消息循环问题,新手求教.
- 请问:在VC中 怎样实现对话框中用鼠标拖动位图移动?
- VC 中如何让程序 在指定的时刻 执行相应的命令
- new CDynLinkLibrary(mydll); 这个怎么delete.
- 如何检测是否有内存泄漏呀?
- 近期本人将提供优秀电子书交流的FTP空间
- 满分求InstallShield Develop V8.0.118的东方语言包~~~~~~~~~~~~~,如果有,不够再加,全给你也行!
- GBK简体繁体怎样相互转换
- 一个奇怪的问题,资深专家入内!
- CDC和ODBC的简单问题!请大家尽快解答!爆加分!
- 如何使用outlook自动化编程??
- odbc 、vc、 CDBException 的m_nRetCode=1008是什么错误,如何解决?
while(Current->next!=NULL&&strcmp(newstr,oldstr)>0)
{
memset(oldstr,0,sizeof(oldstr));
sprintf(oldstr,"%s\t%s\t%s\t%s\t%s",Current->substr,Current->sfztjm,Current->zdztjm,Current->ch,Current->xx);
Prior=Current;
Current=Current->next;
} 中memset(oldstr,0,sizeof(oldstr));
sprintf(oldstr,"%s\t%s\t%s\t%s\t%s",Current->substr,Current->sfztjm,Current->zdztjm,Current->ch,Current->xx);位置不对
正确的应为
while(Current->next!=NULL&&strcmp(newstr,oldstr)>0)
{
Prior=Current;
Current=Current->next;
memset(oldstr,0,sizeof(oldstr));
sprintf(oldstr,"%s\t%s\t%s\t%s\t%s",Current->substr,Current->sfztjm,Current->zdztjm,Current->ch,Current->xx); } 看来这里人气不佳啊…………