| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 325 人关注过本帖
标题:谁能帮忙debuging一下,我只知道在特定的情况下会出错,但不知道为什么
只看楼主 加入收藏
ian116
Rank: 1
等 级:新手上路
帖 子:28
专家分:2
注 册:2009-5-15
结帖率:85.71%
收藏
 问题点数:0 回复次数:0 
谁能帮忙debuging一下,我只知道在特定的情况下会出错,但不知道为什么
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>



int compare(MailNode *cursorPoint,MailNode *maxPoint)
{
  if (maxPoint->year<cursorPoint->year){
    return 1;
  }
  else{
    return 0;
  }
  if (maxPoint->month<cursorPoint->month){
    return 1;
  }
  else{
    return 0;
  }
  if (maxPoint->day<cursorPoint->day){
    return 1;
  }
  else{
    return 0;
  }
  if (maxPoint->hour<cursorPoint->hour){
    return 1;
  }
  else{
    return 0;
  }
  if (maxPoint->minute<cursorPoint->minute){
    return 1;
  }
  else{
    return 0;
  }
  if (maxPoint->second<cursorPoint->second){
    return 1;
  }
  else{
    return 0;
  }
}



int sort(MailNode *messageList){
MailNode *cursorPoint, *preCursorPoint;
MailNode *maxPoint=NULL, *preMaxPoint;
MailNode *prePoint;
MailNode *temp;
//loop n-2 times the list
currentmailnum=
for(prePoint = messageList;prePoint->next->next != NULL;
    prePoint = prePoint->next){
  if (maxPoint == NULL){
    maxPoint = prePoint;
    preMaxPoint = prePoint;
  }
  else{
    maxPoint = prePoint->next;
    preMaxPoint = prePoint;
  }
  for(cursorPoint = maxPoint->next,preCursorPoint = maxPoint;
      cursorPoint != NULL;
      preCursorPoint = cursorPoint,cursorPoint = cursorPoint ->next){
     //if current is big than maxpoint
    if(compare(cursorPoint,maxPoint) == 1){
      //maxpoint=biger one
      maxPoint = cursorPoint;
      preMaxPoint = preCursorPoint;
    }
  }
  //printf("%d", maxPoint->year);
  if(maxPoint != prePoint->next){
    if(prePoint->next!= preMaxPoint){
      temp = prePoint->next->next;
      prePoint->next->next = maxPoint->next;
      maxPoint->next = temp;
      preMaxPoint->next = prePoint->next;
      prePoint->next = maxPoint;
    }
    else {
      prePoint->next->next = maxPoint->next;
      maxPoint->next = prePoint->next;
      prePoint->next = maxPoint;
    }
  }
}
return 0;
}





MailNode *reverse(MailNode *messageList,int mailnum)
{
   MailNode *temptail = NULL;
   MailNode *temp;

   while( messageList != NULL ) {
      temp = messageList->next;
      messageList->next = temptail;
      temptail = messageList;
      messageList = temp;
   }
   return( temptail );
}



// Print the list. The heard is messageList and the tail is NULL.
void printlist(MailNode *messageList, int currentmailnum)
{
  int i=1;
  MailNode *temp;
  // use temporary point *temp read the list from messageList to NULL
  for(temp=messageList;temp!=NULL;temp=temp->next){
  temp->msgNum = i;
  //"->" ponit to current mail
  if (i==currentmailnum){
    printf("->");
  }
  else{
    printf("  ");
  }
  printSynopsis( temp );
  i++;
  }
}

int main(int argc, char* argv[])
{
  MailNode *messageList = NULL; // list of messages
  MailNode *temp=NULL;
  MailNode *lastmessageList=NULL;

  FILE *fp = NULL;
  
  int currentmailnum=1;
  int mailnum=0;

  Boolean showlist=TRUE;
  char lastcommand;
  char c;
  char command[MAXLLENGTH];  // mail client command
  char *search;
  

       case 'o': case 'O':
          sort(messageList);
          if(showlist){
          printlist(messageList,currentmailnum);
          }
          else{
            printcurruntmail(currentmailnum,messageList);
          }      
        break;




      reverse: case 'r': case 'R':
      messageList=reverse(messageList,mailnum);
        if(showlist){
        printlist(messageList,currentmailnum);
        }
        else{
          printcurruntmail(currentmailnum,messageList);
        }
        lastcommand='r';      
        break;




  return 0;
}


我可以单独进行case r,或者进行case o并且重复多少遍都没有问题。我也可以先进行case o,紧接着进行case r,但是我却不能进先进行case r,紧接着进行case o.只要先运行case r在运行case o就会有一个死循环。打开gdb看,好像是在sort(messageList)那个函数里的
 for(cursorPoint = maxPoint->next,preCursorPoint = maxPoint;
      cursorPoint != NULL;
      preCursorPoint = cursorPoint,cursorPoint = cursorPoint ->next){
     //if current is big than maxpoint
    if(compare(cursorPoint,maxPoint) == 1){
      //maxpoint=biger one
      maxPoint = cursorPoint;
      preMaxPoint = preCursorPoint;
    }
  }
一直转。请问为什么啊
搜索更多相关主题的帖子: debuging 
2009-10-16 11:35
快速回复:谁能帮忙debuging一下,我只知道在特定的情况下会出错,但不知道为什么 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011949 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved