请高手帮忙分析一下面的代码有什么问题
谢谢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;
}

解决方案 »

  1.   

    问题解决
    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);  } 看来这里人气不佳啊…………