Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用指针,做的RE的注意了

Posted by huangchang9001 at 2011-07-08 18:55:45 on Problem 1760
注意字符串比较大小时,要先判断p是否是空指针即p==NULL,如果你们空指针比较就会RE
while(p!=NULL&&strcmp(s->pathname,p->pathname)>0) 
{
    t=p;
    p=p->brother;					
}
这是对的
下面是错的
while(strcmp(s->pathname,p->pathname)>0&&p!=NULL) 
{
    t=p;
    p=p->brother;					
}
虽然只是顺序颠倒了,后面是先运行函数strcmp(s->pathname,p->pathname),而p是空指针,p->pathname根本不是字符串,所以会错误!

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator